Jump to content

Arrays Erro


jSherz
 Share

Recommended Posts

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...