Game Development Reference
In-Depth Information
An if statement allows you to perform calculations and string multiple conditions
together with logical operators. It works the way you would expect if you are already
familiar with if statements in programming languages like Java or C. Table 8.1 lists
the possible operators supported by the conditions in an if statement.
TAble 8.1
Possible Operators in
script conditions
OPERATOR
ExPlANATION
ExAMPlE
==
equality
if(resources == 1) fire(consume)
Fire consume node when the number of resources equals one.
!=
nonequality
if(Upgrades != 0) fire(Upgrade)
Fire Upgrade node when the number of resources is not zero.
<=, <, >=, >
relational
if(resources <= 3) fire(Produce)
Fire Produce node as long as the number of resources is
equal to or smaller than three.
+, -
additive
if(Upgrades + 2 < resources - 1) fire(Produce)
Fire Produce node when the number of upgrades plus two is
smaller than the number of resources minus one.
*, /, %
multiplicative
if(Upgrades * 2 > resources / 3) fire(Upgrade)
Fire Upgrade node when the number of upgrades times two
is larger than the number of upgrades divided by three.
The % sign is used for modulo: if (resources % 4 == 2) fire
(Upgrade) Fire Upgrade node if the number of resources
equals 2, 6, 10, and so on.
&&
Logical and
if(resources > 4 && Upgrades < 2) fire(Upgrade)
Fire Upgrade node when there are more than four resources
and fewer than two upgrades.
||
Logical or
if (resources > 6 || Upgrades > 2) fire(consume)
Fire consume node when there are more than six resources
or more than two upgrades.
exTra cOmmands
Apart from the various kinds of ire commands, there are a few extra commands you
can use in a script for an artificial player:
stopDiagram(message)
Stops the execution of the diagram immediately, very much like an end condition
does. You can put a string of text in the parameter. If you have more than one artifi-
cial player, you might want to use a different message in the script of each player to
let you know which player stopped the diagram. When executing multiple runs (see
“Collecting Data from Multiple Runs”), the tool will keep track of how many times
each message appeared and let you know in a dialog box as the runs take place. This
will enable you to collect statistics on what causes a diagram to stop.
 
 
Search WWH ::




Custom Search