View unanswered posts | View active topics It is currently Tue Apr 21, 2026 5:41 am



Reply to topic  [ 2 posts ] 
 Scripting: Arrays 
Author Message
Ambassador
User avatar

Joined: Mon Feb 09, 2004 3:00 am
Posts: 3141
Location: Kansas
Unread post Scripting: Arrays
Arrays can be thought of as containers for common items. Basically an easier
way of doing some things than with variables.

With normal variables you would setup something like:
setVar $sector1 1
setVar $sector2 2
setVar $sector3 3
...
setVar $sector20000 20000

Kind of time consuming and referencing them would be a nightmare - besides I
really don't want carpal-tunnel.

With arrays you could setup a loop that would be something like:

setVar $i 1 // init the var $i to equal 1
while ($i <= SECTORS) // while value of $i <= value of SECTORS (SECTORS number of sectors in TWX database)
setVar $sector[$i] $i // set $sector[$i] to value of $i ($sector[1] = 1)
add $i 1 // increment our counter so no endless loop
end

The above example shows dynamic arrays. Dynamic arrays are slower than static
arrays from what I understand, but with dynamic arrays you don't have to worry
as much about going beyond the boundary (working with an array that is set to say
5000, and you want to go to 5001).

Static arrays are initialized to a set size and the example above would be:

setArray $sector SECTORS // Each $sector[Number] has a value of 0 until changed
// $sector[1] = 0, $sector[2]= 0, ... $sector[20000] = 0.
setVar $i 1
while ($i <= SECTORS)
setVar $sector[$i] $i
add $i 1
end

No difference in the code except for initing the array.

k, the above examples don't do anything practical so....

# Get a list of deployed figs

setVar $myCount 0 // Counter for number of sectors with figs
setVar $figsFile GAMENAME & ".figs" // setup our file to write to (GAMENAME stored in TWX)
send "'Updating fighter list*" // Send SS so our corpies know we are "away"

delete $figsFile // Delete the old file if it exists
setarray $fighter SECTORS // Set our static array
send "cn1qqg" // send cn1 command to go to pure text, no ANSI
as it seems faster quits the computer and lists figs
waitfor "===" // Waitfor waits on the text shown.

:buildFigArray // label we will use to return to
setTextTrigger Corpfig :addtoList "Cor" // trigger for corp figs
setTextTrigger PersFig :addtoList "Per" // trigger for personal figs
setTextTrigger ListDone :buildFigSec "Command" // trigger for when we are done
pause // pause - waits for trigger activation

:addtoList
KillAllTriggers // killalltriggers - better to kill seperate
getword currentline $figSector 1 // get the 1st word of the line we got from the trigger
setvar $fighter[$figsector] $figsector // set our array to something like $fighter[11] to a value of 11
add $myCount 1 // add $myCount for our total sectors with figs
goto :buildFigArray // go back to check for additional figged sectors

:buildFigSec // label we go to after the fighter list runs
setVar $figSecCounter 11 // $figSecCounter set to 11 - can't have figs in 1-10
while ($figSecCounter <= SECTORS) // while our counter is less than sectors
if ($fighter[$figSecCounter] > 0) // if the value in our array is > 0
setSectorParameter $figSecCounter "FigSec" TRUE // we have a fig, set the setSectorParameter to true
else // else
setSectorParameter $figSecCounter "FigSec" FALSE // we don't have a fig set the parameter to false
end // end the if check
add $figSecCounter 1 // add 1 to our counter
end // end the while

...... // script continues on

The reason for my creating the array of fighters is that it is used later.

_________________
               / Promethius / Enigma / Wolfen /

"A man who has no skills can be taught, a man who has no honor has nothing."


Wed Nov 26, 2008 9:51 pm
Profile ICQ
Ensign
User avatar

Joined: Mon Jul 23, 2007 6:20 pm
Posts: 288
Location: United Kingdom
Unread post Re: Scripting: Arrays
Very interesting many thanx.
Tried using arrays a few times and i just get totally lost!!
I'll read that a few times and have a play with them.
Cheers Prome.

_________________
Gul D'Tek (The Cardassian Hitman)
ICQ - 446445340

I'm a TW and #SD# ing you was my idea!

Very funny, Scotty. Now beam down my clothes.~ J.T.Kirk


Sat Jan 03, 2009 1:17 pm
Profile ICQ
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

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