|
|
|
Online Scripting Reference
|
|
setVar
|
Purpose
|
Sets the value of a variable.
|
|
Syntax
|
setVar var {value}
var: The name of the variable to set.
{value}: The value to place into the variable.
|
|
Notes
|
|
|
Example
|
# calculate exactly how many trips we're making
# and how much we're carrying on our last trip
setVar $trips $quantity
divide $trips $holds
setVar $x $trips
multiply $x $holds
setVar $lastTrip $quantity
subtract $lastTrip $x
if ($lastTrip = 0)
setVar $lastTrip $holds
else
add $trips 1
end
|
| ElderProphet - 28 January 2004 at 10:45 PM (EST) |
setVar is a very powerful command. You can do a seemingly unlimited number of math operations with just a single setVar line, as follows:
setVar $test (((((3+2)*6)-10)/5)+1)
# Result is 5
Its good practice to group your operations so they will be calculated from the innermost to the outermost.
You can use setVar to concatenate text as well, and its much simpler than mergeText. E.g.:
setVar $subliminal "Eat Popcorn " & "and Drink Coke."
setVar $log "logs\" & (SECTORS/1000) & "K_Sectors.txt"
setVar $result $planet1 & , & $planet2 & , $planet3
setVar $EOL CURRENTLINE & " @EOL"
setVar is not case sensitive. $eol is the same as $EOL, and the same as $EoL. Also, any text without quotes around it will be made uppercase, and such text can't have any spaces in it.
TWX will coerce variables into integers whenever possible, even if you entered the variable as text (string). Therefore you can use setVar in the following methods:
setVar $number1 (0-3)
setVar $number2 "-3"
# Both are -3
setVar $result1 ((0-3)*"-10")
setVar $result2 ("-3"*(0-10))
# Both are 30
The Boolean values of TRUE and FALSE will be treated as 1 and 0, respectively, in any calculations. Note also that the Boolean logic is derived at the beginning of the operation, before any of the other operations are performed, and will not change states once its been determined (kinda like Shroedinger's cat). E.g.:
setVar $test 3+true
setVar $test ($test*2)+($test<5)
# Result is 9
|
Return to item listing |
|
|