View unanswered posts | View active topics It is currently Sun Apr 19, 2026 10:31 am



Reply to topic  [ 2 posts ] 
 Question about WHILE 
Author Message
Ensign

Joined: Wed Nov 06, 2002 3:00 am
Posts: 270
Unread post 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.


Tue Jun 14, 2011 1:05 am
Profile
Veteran Op
User avatar

Joined: Thu Jun 02, 2005 2:00 am
Posts: 5558
Location: USA
Unread post 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

_________________
May the unholy fires of corbomite ignite deep within the depths of your soul...

1. TWGS server @ twgs.navhaz.com
2. The NavHaz Junction - Tradewars 2002 Scripts, Resources and Downloads
3. Open IRC chat @ irc.freenode.net:6667 #twchan
4. Parrothead wrote: Jesus wouldn't Subspace Crawl.

*** SG memorial donations via paypal to: dpocky68@booinc.com
Image


Tue Jun 14, 2011 1:21 am
Profile ICQ WWW
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by wSTSoftware.