I am doing a couple of while loops in a script I am working on, getting unexplored sectors in a new local game that has a lot of sectors I haven't been to. I am pausing the script to check variables and triggers, and I noticed something odd with the loop as I have it written in the following code, and some other way's I tried to write the code. It seems to be adding an extra variable to the second array, with a zero value.
Code:
:getUnexplored
WHILE ($i < $checkQuant)
getSector $i $currSect
IF ($currSect.explored = "YES")
add $i 1
Else
setVar $notExplored[$x] $i
add $i 1
add $x 1
END
END
# This code block sets another array, and resets our variables
setVar $z $x
setArray $unExplored $z
setVar $i 1
setVar $x 1
setVar $y 1
# This code block sets a working array from the storage array,
# which will be smaller and faster to work with
:workingArray
WHILE ($x < $z)
setVar $unExplored[$y] $notExplored[$x]
add $y 1
add $x 1
END
setVar $i 1
setVar $x 1
setVar $y 1
I didn't include the code block but there is one before this where I originally set $i, $x, $y and $z to 1 before I started that first routine, and set $checkQuant to 100 so I didn't get a whole list of 20,000 variables in the first aray to have to wait through. I tried using <> and <= both as the operators in the While routine, does the same thing. Anyone see why I'm getting that extra array variable with a zero value doing it this way?
I can think how I can keep it from adding a zero value variable in the second array, by adding an AND in there and a 2nd conditional, like
WHILE ($i < $checkQuant) AND ($i <> 0)
and
WHILE ($x < $z) AND ($notExplored[$x] <> 0)
Or I could add an IF routine that checks to make sure that the array variable isn't a zero.
But I was thinking there must be another cleaner way to do it.