Sign in to follow this  
Followers 0
Makalele

Why it causes this error?

7 posts in this topic

Here's a part of my code:

...
For $rScan=0 to 3
        If $Potions[1][$rScan] = "h" Then ExitLoop
Next
If $Potions[1][$rScan] = "h" Then
...

Here's a declaration of $Potions array:

Dim $Potions[4][4]

And here's an error:

Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
If $Potions[1][$rScan] = "h" Then
If ^ ERROR

Why???


Share this post


Link to post
Share on other sites



It means that whatever you are populating "Dim $Potions[4][4]" with, excedes the bounds of it.

Without further code, no other info is possible.

I know what it means, but i don't know why it happens. Here's a loop loop from 0 do 3 so it can't "go out" the array, same with '1'.

Ok so here's a whole function:

Func Chicken()
    CheckLife()
    CheckMana()
    If $Life < $MinRV_HP And TimerDiff($LastDrinkRvHealth)>1000 Then 
        For $rScan=0 to 3
            If $Potions[0][$rScan] = "r" Then ExitLoop
        Next
        If $Potions[0][$rScan] = "r" Then
            Send("1")
            $LastDrinkRvHealth=TimerInit()
            $Potions[0][$rScan] = " "
            Return 1
        Else
            If $Life<=$ChickenHP Then 
                SaveAndExitGame()
                Return -1
            EndIf
        EndIf
    EndIf
    If $Mana < $MinRV_MP And TimerDiff($LastDrinkRvMana)>1000 Then 
        For $rScan=0 to 3
            If $Potions[0][$rScan] = "r" Then ExitLoop
        Next
        If $Potions[0][$rScan] = "r" Then
            Send("1")
            $LastDrinkRvHealth=TimerInit()
            $Potions[0][$rScan] = " "
            Return 1
        Else
            If $Mana<=$ChickenMP Then 
                SaveAndExitGame()
                Return -1
            EndIf
        EndIf
        Send("1")
        $LastDrinkRvHealth=TimerInit()
        Return 1
    EndIf
    If $Life < $MinHP And TimerDiff($LastDrinkHealth)>2000 Then
        For $rScan=0 to 3
            If $Potions[1][$rScan] = "h" Then ExitLoop
        Next
        If $Potions[1][$rScan] = "h" Then
            Send("2")
            $LastDrinkHealth=TimerInit()
            $Potions[1][$rScan] = " "
        Else
            For $rScan=0 to 3
                If $Potions[2][$rScan] = "h" Then ExitLoop
            Next
            If $Potions[2][$rScan] = "h" Then
                Send("3")
                $LastDrinkHealth=TimerInit()
                $Potions[2][$rScan] = " "
            EndIf
        EndIf
    EndIf
    If $Mana < $MinMP And TimerDiff($LastDrinkMana)>2000 Then
        For $rScan=0 to 3
            If $Potions[3][$rScan] = "m" Then ExitLoop
        Next
        If $Potions[3][$rScan] = "m" Then
            Send("4")
            $LastDrinkMana=TimerInit()
            $Potions[3][$rScan] = " "
        EndIf
    EndIf
    Return 0
EndFunc

Share this post


Link to post
Share on other sites

Look at the commented line.

Func Chicken()
    CheckLife()
    CheckMana()
    If $Life < $MinRV_HP And TimerDiff($LastDrinkRvHealth)>1000 Then 
        For $rScan=0 to 3
            If $Potions[0][$rScan] = "r" Then ExitLoop
        Next
        If $Potions[0][$rScan] = "r" Then  ;<<<<<<<< $rScan = 4 at this point because the for loop exits when it is greater than 3
            Send("1")
            $LastDrinkRvHealth=TimerInit()
            $Potions[0][$rScan] = " "
            Return 1
        Else
            If $Life<=$ChickenHP Then 
                SaveAndExitGame()
                Return -1
            EndIf
        EndIf
    EndIf
    If $Mana < $MinRV_MP And TimerDiff($LastDrinkRvMana)>1000 Then 
        For $rScan=0 to 3
            If $Potions[0][$rScan] = "r" Then ExitLoop
        Next
        If $Potions[0][$rScan] = "r" Then
            Send("1")
            $LastDrinkRvHealth=TimerInit()
            $Potions[0][$rScan] = " "
            Return 1
        Else
            If $Mana<=$ChickenMP Then 
                SaveAndExitGame()
                Return -1
            EndIf
        EndIf
        Send("1")
        $LastDrinkRvHealth=TimerInit()
        Return 1
    EndIf
    If $Life < $MinHP And TimerDiff($LastDrinkHealth)>2000 Then
        For $rScan=0 to 3
            If $Potions[1][$rScan] = "h" Then ExitLoop
        Next
        If $Potions[1][$rScan] = "h" Then
            Send("2")
            $LastDrinkHealth=TimerInit()
            $Potions[1][$rScan] = " "
        Else
            For $rScan=0 to 3
                If $Potions[2][$rScan] = "h" Then ExitLoop
            Next
            If $Potions[2][$rScan] = "h" Then
                Send("3")
                $LastDrinkHealth=TimerInit()
                $Potions[2][$rScan] = " "
            EndIf
        EndIf
    EndIf
    If $Mana < $MinMP And TimerDiff($LastDrinkMana)>2000 Then
        For $rScan=0 to 3
            If $Potions[3][$rScan] = "m" Then ExitLoop
        Next
        If $Potions[3][$rScan] = "m" Then
            Send("4")
            $LastDrinkMana=TimerInit()
            $Potions[3][$rScan] = " "
        EndIf
    EndIf
    Return 0
EndFunc

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I know why. Run this code.

For $rScan=0 to 3
        MsgBox(0, "", $rScan)
Next
MsgBox(0, "", $rScan)

It seems the loop repeats until $rScan = 4

Ah! Bowmore beat me to it. ;)

So you need to subtract 1 from $rScan at the appropriate places to get the expected result.

I think it had too many portions of chicken. :blink:

Edited by czardas

Share this post


Link to post
Share on other sites

Hell yeah, it was it ^^ Thanks!! T/C


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  
Followers 0