jSherz Posted October 15, 2009 Share Posted October 15, 2009 I get an error when using this function: Func MakePos($posx, $posy) Local $pos[2][4] For $i = 0 To 4 Step 1 $ran1 = Random(0, 4) $ran2 = Random(0, 4) $ran3 = Random(1, 2) $ran4 = Random(1, 2) If $ran3 = 1 Then $pos[0][$i] = $posx + $ran1 $pos[1][$i] = $posy - $ran2 Else $pos[0][$i] = $posx - $ran1 $pos[1][$i] = $posy + $ran2 EndIf Next Return $pos EndFunc The error: http://bayimg.com/faedMaaCi Link to comment Share on other sites More sharing options...
trancexx Posted October 15, 2009 Share Posted October 15, 2009 Declare your array as Local $pos[2][5] 0, 1, 2, 3, 4 <- that's 5 elements ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Paulie Posted October 15, 2009 Share Posted October 15, 2009 I get an error when using this function: Func MakePos($posx, $posy) Local $pos[2][4] For $i = 0 To 4 Step 1 $ran1 = Random(0, 4) $ran2 = Random(0, 4) $ran3 = Random(1, 2) $ran4 = Random(1, 2) If $ran3 = 1 Then $pos[0][$i] = $posx + $ran1 $pos[1][$i] = $posy - $ran2 Else $pos[0][$i] = $posx - $ran1 $pos[1][$i] = $posy + $ran2 EndIf Next Return $pos EndFunc The error: http://bayimg.com/faedMaaCi You defined the array: Local $pos[2][4] When you count from 0 to 4, that actually 5 elements. Change you loop to this Func MakePos($posx, $posy) Local $pos[2][4] For $i = 0 To 4 Step 1 $ran1 = Random(0, 4) $ran2 = Random(0, 4) $ran3 = Random(1, 2) $ran4 = Random(1, 2) If $ran3 = 1 Then $pos[0][$i] = $posx + $ran1 $pos[1][$i] = $posy - $ran2 Else $pos[0][$i] = $posx - $ran1 $pos[1][$i] = $posy + $ran2 EndIf Next Return $pos EndFunc Link to comment Share on other sites More sharing options...
jSherz Posted October 15, 2009 Author Share Posted October 15, 2009 Declare your array as Local $pos[2][5] 0, 1, 2, 3, 4 <- that's 5 elements Many thanks!!! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now