| www.ClassicTW.com https://mail.black-squirrel.com/ |
|
| Question about WHILE https://mail.black-squirrel.com/viewtopic.php?f=15&t=31690 |
Page 1 of 1 |
| Author: | SteveH_66 [ Tue Jun 14, 2011 1:05 am ] |
| Post subject: | Question about WHILE |
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. |
|
| Author: | Singularity [ Tue Jun 14, 2011 1:21 am ] |
| Post subject: | Re: Question about WHILE |
I don't think you need all of those index trackers. Here's one way to do it in 2 different forms. Code: setArray $unexplored SECTORS setVar $idx 11 setVar $count 0 while ($idx <= SECTORS) if (SECTOR.EXPLORED[$idx] <> "YES") add $count 1 setVar $unexplored[$idx] TRUE setVar $list[$count] $idx end add $idx 1 end |
|
| Page 1 of 1 | All times are UTC - 5 hours |
| Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |
|