Jump to content
Sign in to follow this  
jSherz

Arrays Erro

Recommended Posts

jSherz

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

Share this post


Link to post
Share on other sites
trancexx

Declare your array as

Local $pos[2][5]

0, 1, 2, 3, 4 <- that's 5 elements


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
Paulie

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

Share this post


Link to post
Share on other sites
jSherz

Declare your array as

Local $pos[2][5]

0, 1, 2, 3, 4 <- that's 5 elements

Many thanks!!!

Share this post


Link to post
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
Sign in to follow this  

×