View unanswered posts | View active topics It is currently Sat Apr 18, 2026 3:13 am



Reply to topic  [ 14 posts ] 
 Using while loops to validate a sector 
Author Message
Ambassador
User avatar

Joined: Wed Nov 12, 2008 8:57 am
Posts: 3554
Location: Long Beach, CA
Unread post Using while loops to validate a sector
I want to use nested while loops to validate whether I should move to a sector, carry out and operation, then move to the next. Its actually 4 steps.

1. Generate a topdown list of sectors in the universe (however many there are: 30k, 20k, 5k) less sectors 1-10, STARDOCK, ALPHA_CENTARI, and RYLOS

2. Then I want to step through the resulting list using a while loop
Code:
#set the universe size
setVar $uni_size 20000
#read all the sectors to an array
readtoarray $sector __all_sector.txt
#set the index for the array $sector
setvar $i 1
setVar $s $Sector[$i]
#outside while loop, will run until the loop reach 20k
while ($s <= $uni_size)

    #if condition to remove sectors 1-10, SD, AC and Rylos
    if (($sector =< 10) or ($sector = STARDOCK) or ($sector = ALPHA_CENTAURI) or ($sector = RYLOS))
         add $i 1
    else
         #inside while loop, I want to write all sectors in the $sector array
         #less the sectors in the $my_sect array
         #read the list of my sectors into an array
         readtoarray $my_sect __my_sectors.txt
         #set the index for the array $my_sect
         setvar $r 1
         setVar $m $my_sect[$r]
         while ($s <> $m)
               add $r 1
         end
     #write sector to a file - Not sure of the code to do this
     write "sectors_left.txt" $s
     add $i 1
     end
end


H

_________________
Helix
Do I really look like a guy with a plan? You know what I am? I'm a dog chasing cars.
Lest we forget
I had to ask myself WWSGD?


Mon May 21, 2012 11:02 pm
Profile WWW
Veteran Op
User avatar

Joined: Sat Dec 29, 2007 5:06 pm
Posts: 2059
Location: Oklahoma
Unread post Re: Using while loops to validate a sector
I don't have time to really run it until I get home but here are a couple changes I use to simplify somethings:

using "SECTORS" makes the script useable in all games without modifying since it pulls from the TWX database.
Looks like you had it where it would have been adding a 1 to $i in two locations every loop meaning it could skip 3 or 4 sectors total, not a big deal but it might be one you needed.
I am not sure what you inputting using the text files so I am just gonna guess it is all sectors in the one?
the write "sectors_left.txt" $sector would need to be moved to the location in the script of where if it didn't make it to the desired sector?

Code:
#set the index for the array $sector
setVar $sector 11
#outside while loop, will run until the loop reach 20k
while ($sector <= SECTORS)
    #if condition to remove sectors 1-10, SD, AC and Rylos
    if (($sector = STARDOCK) or ($sector = ALPHA_CENTAURI) or ($sector = RYLOS))
         goto :skip
    else
         #inside while loop, I want to write all sectors in the $sector array
         #less the sectors in the $my_sect array
         #read the list of my sectors into an array
         readtoarray $my_sect __my_sectors.txt
         #set the index for the array $my_sect
         setvar $r 1
         setVar $m $my_sect[$r]
         while ($sector <> $m)
               add $r 1
         end
     #write sector to a file - Not sure of the code to do this
     write "sectors_left.txt" $sector
     :skip
     add $sector 1
     end
end

_________________
T0yman (Permanently Retired since 2012)
Proverbs 17:28 <-- Don't know it, most should it would stop a lot of the discussions on here.


Tue May 22, 2012 9:58 am
Profile ICQ YIM WWW
Ambassador
User avatar

Joined: Wed Nov 12, 2008 8:57 am
Posts: 3554
Location: Long Beach, CA
Unread post Re: Using while loops to validate a sector
That looks a lot cleaner than mine. I will give it a try. I try out the logic of it in my head and I get all twisted around.

The end result is to get a top down list of every sector in the universe minus, my bubble sectors, sectors 1-10 (starting at 11 was so simple but I couldnt see it) , SD, AC, and Rylos.

H

_________________
Helix
Do I really look like a guy with a plan? You know what I am? I'm a dog chasing cars.
Lest we forget
I had to ask myself WWSGD?


Tue May 22, 2012 10:36 am
Profile WWW
Commander
User avatar

Joined: Fri Jun 09, 2006 2:00 am
Posts: 1401
Location: Canada
Unread post Re: Using while loops to validate a sector
Couldn't help myself. Try This:
Code:
setvar $File1 "sectors_left.txt"
setvar $File2 "sectors_uFig.txt"
delete $File1
delete $File2
ReadToArray $my_sect "__my_sectors.txt"

SetVar $sector 11

While ($Sector <= SECTORS)
    If (($Sector <> STARDOCK) AND ($Sector <> ALPHA_CENTAURI) AND ($Sector <> RYLOS))
       SetVar $r 1
       While ($r <= $my_sect)
         if ($my_sect[$r] = $Sector)
            goto :_NEXT_
         end
         add $r 1
       End
       Write $File1 $Sector
       GetSectorparameter $Sector "FIGSEC" $F
       If ($F = 0)
         Write $File2 $Sector
       End
    End
    :_NEXT_
    Add $Sector 1
End



Borrowed Toymans routine. Hope thi sworks for you.

_________________
----------------------------
-= QUANTUM Computing 101: 15 = 3 x 5 ... 48% of the time.


Tue May 22, 2012 5:27 pm
Profile ICQ YIM
Commander
User avatar

Joined: Tue Oct 07, 2003 2:00 am
Posts: 1134
Location: Augusta, GA
Unread post Re: Using while loops to validate a sector
Something you'll often need to do is create a "boolean array", meaning it is used as a true/false test. So in the above scenario, you could create a SECTOR-sized array called $skip, and then set the sectors 1-10, STARDOCK, RYLOS, AND ALPHACENTAURI to TRUE (or 1), as the default value is FALSE (or zero). Then you can use this as the one test for whether a sector should be processed or not. This one test of a static array value is very fast compared to multiple tests, but that is only important if you are doing something speed-sensitive. But even when speed isn't an issue, this approach is often cleaner and simpler, especially compared to several nested while loops / if statements.

Let me know if you need an example.

_________________
Claim to Fame: only guy to ever crack the TW haggle algorithm, and fig/shield/hold price formula, twice.


Tue May 22, 2012 8:24 pm
Profile WWW
Ambassador
User avatar

Joined: Wed Nov 12, 2008 8:57 am
Posts: 3554
Location: Long Beach, CA
Unread post Re: Using while loops to validate a sector
Elder, I do need an example. I also found that I must test for another condition: do I have a fig in the sector. Thank you for your input.

T0y, your loop seemed to go infinite. I am still looking into why. It pegged the CPU at 50%. LS yours worked and I got what I wanted out of the sequence but found I also need to test for a fig in the sector too.

I really want to say thanks to all of you for your help.

H

_________________
Helix
Do I really look like a guy with a plan? You know what I am? I'm a dog chasing cars.
Lest we forget
I had to ask myself WWSGD?


Tue May 22, 2012 11:13 pm
Profile WWW
Commander

Joined: Sun Feb 25, 2001 3:00 am
Posts: 1838
Location: Guam USA
Unread post Re: Using while loops to validate a sector
Toymans script had an error ..

the last 3 lines
Code:
     add $sector 1
     end
end


Should have been :
Code:
    end
    add $sector 1
end

_________________
TWGS V2 Vids World on Guam Port 2002
Telnet://vkworld.ddns.net:2002
Discord @ DiverDave#8374
Vid's World Discord

Founding Member -=[Team Kraaken]=- Ka Pla

Image
Winners of Gridwars 2010
MBN Fall Tournament 2011 winners Team Kraaken
Undisputed Champions of 2019 HHT Just for showing up!

The Oldist , Longist Running , Orginal Registered Owner of a TWGS server :
Vids World On Guam


Wed May 23, 2012 4:00 am
Profile WWW
Commander
User avatar

Joined: Fri Jun 09, 2006 2:00 am
Posts: 1401
Location: Canada
Unread post Re: Using while loops to validate a sector
Vid Kid wrote:
Toymans script had an error ..

the last 3 lines
Code:
     add $sector 1
     end
end


Should have been :
Code:
    end
    add $sector 1
end


actually, the problem was here:
Code:
setvar $r 1
setVar $m $my_sect[$r]
while ($sector <> $m)
      add $r 1
end


$sector, at some point, would forever be <> to $m.

I'll wont steal EPs Thunder and post an example of what he is talking about. But I would like to point out that his idea is exactly like populating an array of deployed fighters for use in a Foton or PDrop script: if ($Fig[$Adj_HitSector] = TRUE) ...do attack. Or. In the case of excluding Bubble Sectors: if ($List[$Sector] = 0) ...write $Sector to file.

_________________
----------------------------
-= QUANTUM Computing 101: 15 = 3 x 5 ... 48% of the time.


Wed May 23, 2012 6:10 am
Profile ICQ YIM
Veteran Op
User avatar

Joined: Sat Dec 29, 2007 5:06 pm
Posts: 2059
Location: Oklahoma
Unread post Re: Using while loops to validate a sector
I will take the hit, but if you notice in the original I only changed the name not the original sequence :lol: But keep calling it my error I can handle it :)

Glad to help I wish I had the time to test it first but this is what happens shooting from the hip. heh

_________________
T0yman (Permanently Retired since 2012)
Proverbs 17:28 <-- Don't know it, most should it would stop a lot of the discussions on here.


Wed May 23, 2012 6:25 am
Profile ICQ YIM WWW
Commander
User avatar

Joined: Fri Jun 09, 2006 2:00 am
Posts: 1401
Location: Canada
Unread post Re: Using while loops to validate a sector
T0yman wrote:
I will take the hit, but if you notice in the original I only changed the name not the original sequence :lol: But keep calling it my error I can handle it :)


Ha! Good show, ole sport :)

_________________
----------------------------
-= QUANTUM Computing 101: 15 = 3 x 5 ... 48% of the time.


Wed May 23, 2012 6:30 am
Profile ICQ YIM
Commander
User avatar

Joined: Tue Oct 07, 2003 2:00 am
Posts: 1134
Location: Augusta, GA
Unread post Re: Using while loops to validate a sector
So the conventional way to apply multiple conditional tests like you're after is as follows:
Code:
setVar $i 1
while ($i <= SECTORS)
   if ($i > 10)
      if ($i <> STARDOCK) and ($i <> RYLOS) and ($i <> ALPHACENTAURI)
         if (SECTOR.FIGS.OWNER[$i] <> "belong to your Corp") and (SECTOR.FIGS.OWNER[$i] <> "yours")
            gosub :doSomething
         end
      end
   end
   add $i 1
end
I even started at 1 so that we could do the > 10 conditional test. The boolean array idea would create a true/false array of sectors to skip. Since the default value of an array element is zero or FALSE, we'll make an array of sectors to skip, and just set desireable sectors to 1 or TRUE, such as 1-10, SD, Rylos, AC, etc., as follows:
Code:
setArray $skip SECTORS
setVar $i 1
while ($i <= SECTORS)
   if ($i < 11)
      setVar $skip[$i] TRUE
   end
   if ($i = STARDOCK) or ($i = RYLOS) or ($i = ALPHACENTAURI)
      setVar $skip[$i] TRUE
   end
   if (SECTOR.FIGS.OWNER[$i] = "belong to your Corp") or (SECTOR.FIGS.OWNER[$i] = "yours")
      setVar $skip[$i] TRUE
   end
   add $i 1
end
Now it should be trivial for you to add additional criteria to the above example. And then, iterating over the array to actually take action would look something like this:
Code:
setVar $i 1
while ($i <= SECTORS)
   if ($skip[$i] = FALSE)
      gosub :doSomething
   end
   add $i 1
end

Obviously, the :doSomething gosub is up to you, but hopefully the boolean array idea and conditional testing is clearly demonstrated. Further questions / examples?

+EP+

_________________
Claim to Fame: only guy to ever crack the TW haggle algorithm, and fig/shield/hold price formula, twice.


Wed May 23, 2012 1:07 pm
Profile WWW
Ambassador
User avatar

Joined: Wed Nov 12, 2008 8:57 am
Posts: 3554
Location: Long Beach, CA
Unread post Re: Using while loops to validate a sector
Thanks EP, no questions at the moment, I have to put it into practice to see it work.

H

_________________
Helix
Do I really look like a guy with a plan? You know what I am? I'm a dog chasing cars.
Lest we forget
I had to ask myself WWSGD?


Wed May 23, 2012 2:48 pm
Profile WWW
Gameop

Joined: Mon Jan 15, 2007 2:41 am
Posts: 342
Unread post Re: Using while loops to validate a sector
Helix. In my bubble_farm script I use sectorparameters. I have a script that just pulls the bubbles from a list and sets that sectorparm (ex: bubblesec) to true. So when I run my loops to see if I need to go to the sector I just check if figsec and bublesec = true then I warp to that sector. Just another idea.

_________________
Where Chaos Reigns TW Server
chaos-twgs.com:23


Wed May 23, 2012 4:36 pm
Profile ICQ
Ambassador
User avatar

Joined: Wed Nov 12, 2008 8:57 am
Posts: 3554
Location: Long Beach, CA
Unread post Re: Using while loops to validate a sector
The Bounty Hunter wrote:
Helix. In my bubble_farm script I use sectorparameters. I have a script that just pulls the bubbles from a list and sets that sectorparm (ex: bubblesec) to true. So when I run my loops to see if I need to go to the sector I just check if figsec and bublesec = true then I warp to that sector. Just another idea.


Thats a good idea. I could check bubblesec = false and figsec = true to get the sectors outside my bubbles that have my figs. The learning curve just got higher. I need to learn more about using the twx database to pull info from and put info in....

H

_________________
Helix
Do I really look like a guy with a plan? You know what I am? I'm a dog chasing cars.
Lest we forget
I had to ask myself WWSGD?


Wed May 23, 2012 9:04 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 14 posts ] 

Who is online

Users browsing this forum: No registered users and 12 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.