This is the complete list of commands available to you in Smash. First, a
brief index of the commands is given, and a more detailed explanation
follows.
Explanation of Syntax
The syntax of each command is described by listing each command's arguments.
If the argument is given in ()'s, it is a required parameter. If the
argument is given in []'s, it is an optional parameter. The syntax of
each argument type is given as follows:
Argument Type |
Syntax |
number |
one or more digits (no spaces!) |
tag |
one or more letters, digits, or underscores (no spaces!) |
tag-exp |
one or more letters, digits, or underscores (no spaces!), optionally
with {}'s containing expressions that should be evaluated |
lower-tag-exp |
one or more lower case letters, digits, or underscores (no spaces!),
optionally with {}'s containing expressions that should be evaluated;
capital letters are not allowed |
var |
one or more letters, digits, or underscores (no spaces!), with
at least one non-digit character |
var-exp |
one or more letters, digits, or underscores (no spaces!), optionally
with {}'s containing expressions that should be evaluated; the
evaluated string must contain at least one non-digit character |
image |
the filename of an image |
op |
any operator (other than =) that accepts two arguments |
expr |
an expression |
str-exp |
a text string, at least one character long, all on one line,
optionally with {}'s containing expressions that should be
evaluated |
str-expd |
a text string, at least one character long, all on one line,
optionally with {}'s containing expressions that should be
evaluated immediately, and/or with []'s containing expressions
that should be evaluated at time of display |
text |
a text string, at least one character long, that may span multiple
lines provided each line after the first is indented one extra
level; {}'s are allowed; []'s can be used to
embed images |
Text/Image Commands |
Command |
Syntax |
Followed By Code Block? |
Description |
Files |
. | . [text] | No | set the area description text to text | .sma files, outside option blocks |
, | , [text] | No | append text to the current area description text | .sma files, outside option blocks |
; | ; (text) | No | append text to the current area description text, but without an intervening space | .sma files, outside option blocks |
p | p [text] | No | set the action description text to text | .sma files, anywhere, but usually inside option blocks |
P | P [text] | No | append text to the current action description text | .sma files, anywhere, but usually inside option blocks |
A | A (text) | No | append text to the current action description text, but without an intervening space | .sma files, anywhere, but usually inside option blocks |
i | i [number] [image] | No | set the image to display, unless [number] is lower than that of a previous i statement; if [number] and [image] are missing, stops an image from being displayed | .sma files, anywhere |
S | S [number] [str-expd] | No | set status line number to str-expd; if str-expd is absent, erase the status line number; if number is absent, erase all status lines; the value of number for each status line indicates how they should be ordered | .sma files, anywhere |
Inventory Manipulation |
Command |
Syntax |
Followed By Code Block? |
Description |
Files |
a | a (tag-exp) | No | put item tag-exp in the player's inventory | .sma files, anywhere |
d | d [tag-exp] | No | drop item tag-exp from the player's inventory; if tag-exp is omitted, all items (including enumerated) are dropped | .sma files, anywhere |
e | e (tag-exp) = (expr) | No | assign the inventory count of enumerated item tag-exp to expr | .sma files, anywhere |
e | e (tag-exp) (op) (expr) | No | modify the inventory count of enumerated item tag-exp by op expr | .sma files, anywhere |
D | D [tag-exp] | No | drop all regular and enumerated objects from the inventory bag tag-exp; if tag-exp is omitted, all objects are dropped from all inventory bags | .sma files, anywhere |
b | b (tag-exp) | No | switch to the inventory bag (tag-exp) -- note that "0" is the default inventory bag | .sma files, anywhere |
B | B (tag-exp) | No | add the items in the inventory bag (tag-exp) to the current inventory bag -- note that this does NOT remove the items from (tag-exp) | .sma files, anywhere |
Variable Manipulation |
Command |
Syntax |
Followed By Code Block? |
Description |
Files |
s | s (var-exp) = (expr) | No | assign the state variable var-exp the value of expr | location files or functions called from location files |
s | s (var-exp) (op) (expr) | No | modify the state variable var-exp by op expr | location files or functions called from location files |
v | v (var-exp) = (expr) | No | assign the global variable var-exp the value of expr | .sma files, anywhere |
v | v (var-exp) (op) (expr) | No | modify the global variable var-exp by op expr | .sma files, anywhere |
t | t + (var-exp) = (expr) | No | make the timer called var-exp an incrementing timer and set it to expr | .sma files, anywhere |
t | t - (var-exp) = (expr) | No | make the timer called var-exp a decrementing timer and set it to expr | .sma files, anywhere |
t | t + (var-exp) (op) (expr) | No | make the timer called var-exp an incrementing timer and modify it by op expr | .sma files, anywhere |
t | t - (var-exp) (op) (expr) | No | make the timer called var-exp a decrementing timer and modify it by op expr | .sma files, anywhere |
t | t << (expr) | No | rewind all timers by expr (incrementing timers are decremented, and decrementing timers are incremented) | .sma files, anywhere |
t | t >> (expr) | No | fast forward all timers by expr (incrementing timers are incremented, and decrementing timers are decremented) | .sma files, anywhere |
z | z [lower-tag-exp] | No | zero (delete) all state variables; if lower-tag-exp is present, only zero that location's state variables | .sma files, anywhere |
Z | Z | No | zero (delete) all global variables and timers | .sma files, anywhere |
Control Flow |
Command |
Syntax |
Followed By Code Block? |
Description |
Files |
g | g (lower-tag-exp) | No | set the location to jump to to lower-tag-exp | .sma files, inside option blocks |
G | G | Yes | execute the following block of code only if we have just arrived at this location via a g command | .sma files, outside option blocks |
f | f (tag-exp) | No | call the function tag-exp, located elsewhere in the same file | .sma files, anywhere |
f | f (lower-tag-exp1).(tag-exp2) | No | call the function tag-exp2, located in the file lower-tag-exp1.sma | .sma files, anywhere |
~ | ~ (tag) | Yes | defines the start of a function called tag | .sma files, outside code blocks |
r | r (expr) | No | sets the function return value | .sma files, inside functions |
c | c (expr) | Yes | execute the following block of code if expr evaluates to a non-zero value | .sma files, anywhere |
C | C [expr] | Yes | executes the following block of code if expr is missing or evaluates to a non-zero value, and no prior connected c or C command succeeded | .sma files, only immediately after a c or C block |
L | L (expr) | Yes | execute the following block of code if expr evaluates to a non-zero value, then loops back to the L command when it is done | .sma files, anywhere |
R | R (expr) | Yes | execute the following block of code without initially evaluating expr, then loop back and treat the block like an L loop | .sma files, anywhere |
l | l | No | lose the game | .sma files, anywhere |
w | w [str-exp] | No | win the game; if present, str-exp is a |-delimited list of strings to use as Hall of Fame parameters | .sma files, anywhere |
W | W [str-exp] | No | win the game but allow play to continue from that point; if present, str-exp is a |-delimited list of strings to use as Hall of Fame parameters | .sma files, anywhere |
^ | ^ (tag) (str-exp) | Yes | define a move option tag with text str-exp | .sma files, outside option blocks |
* | * (tag) (str-exp) | Yes | define an action option tag with text str-exp | .sma files, outside option blocks |
@ | @ (tag) (str-exp) | Yes | define a constant option tag with text str-exp and make it visible | copts.sma, outside option blocks |
@ | @ (tag) (str-exp) | No | redefine constant option tag to have the text str-exp | .sma files, anywhere |
@ | @ + [tag] | No | make constant option tag visible; if tag is omitted, make all constant options visible | .sma files, anywhere |
@ | @ - [tag] | No | make constant option tag invisible; if tag is omitted, make all constant options invisible | .sma files, anywhere |
Misc. Commands |
Command |
Syntax |
Followed By Code Block? |
Description |
Files |
x | x (expr) | No | set the random number seed | .sma files, anywhere |
! | ! [text] | No | cause an error with str-exp as the error message; useful only when debugging | .sma files, anywhere |
Explanation of Commands
- Command: . [text]
Sets the area description text. This text is used to describe your
surroundings in the game. This is not used inside option code blocks,
but it may be used in conditional code blocks if the description of the area
might change depending on how things are in the game.
- Example 1:
. You are in the middle of a vast canyon. The earth
is dry and cracked. Birds circle about
overhead. You feel very thirsty.
- Example 2:
c s = 0
. There is a switch on the wall. It is turned off.
c s = 1
. There is a switch on the wall. It is turned on.
- Command: , [text]
Appends additional text after previously set area description text.
If no text is supplied, a space character is appended.
Because it involves modifying the same text that the . command does, it is
used in the same contexts. The first example below is functionality equivalent
to Example 2 above but uses more compact code.
- Example 1:
. There is a switch on the wall.
c s = 0
, It is turned off.
c s = 1
, It is turned on.
- Example 2:
. You are in a bright sun room with windows and plants everywhere you look.
c s = 0
, There is a broken wristwatch here that appears to have been
lost, stepped on, and inadvertently kicked into a corner.
See also: the ; command.
- Command: ; (text)
Append additional text after previously set area description text.
This differs from the , command in that it does not insert an intervening
space. Therefore, this command only tends to be used when displaying text
items without spacing.
- Example 1:
. There is a combination lock on the briefcase. It is set to
c combo1 = 0
, A-
C combo1 = 1
, B-
C
, C-
c combo2 = 0
; A-
C combo2 = 1
; B-
C
; C-
c combo3 = 0
; A.
C combo3 = 1
; B.
C
; C.
See also: the , command.
- Command: p [text]
Sets the action text. This text is used to describe what happens
as a result of an action taken by a user. Normally it is used inside option
code blocks, to be executed when an option is selected, although it may be
used outside option blocks in certain situations. It may also be used in the
"start" file to set some introductory text which will be displayed when a
user first starts the game, then never again. (This is a good place to put
instructions.)
- Command: P [text]
Appends additional text after previously set action text. If no
text is supplied, a space character is appended.
Because it involves modifying the same text that the
p command does, it is used in the same contexts.
- Example 1:
* 1 Walk through the force field.
p You start toward the force field,
c d:shield
P but an electric shock throws you back.
C
P and your magnetic shielding protects you. The force field
snaps and flares, but you pass safely into the
room on the other side.
g otherside
- Command: A (text)
Appends additional text after previously set action text. Because it
involves modifying the same text that the p command
does, it is used in the same contexts. This differs from the
P command in that it does not insert an intervening
space. Therefore, this command only tends to be used when displaying text
items without spacing.
- Command: i [number] [image]
This command is used to set an image to be displayed.
Normally, the [number] argument is only present when multiple
i commands could be encountered during a single
turn. When that happens, [number] is used to determine which image command
will take effect. If [number] is present, the effects of a previous
i command will only be overridden if the [number]
is equal to or larger than the [number] in the previous
i command. This is useful in situations where an
i command resides in a location file outside
all option blocks and, in addition, an option block contains an
i command of its own. Usually in these cases, it
is undesirable for the location-level i command to
override the effects of the previously executed i
command from the option block. If the location-level
i command has a priority of 0 and the option block
i command has a higher priority (or none at all),
then the desired effect is achieved.
If [number] is omitted, the highest possible priority is assumed.
If neither a [number] or an [image] is supplied, no image will be displayed.
[number] may not be present if [image] is not also present. Note that
i commands only take effect for the current turn,
not any future turns.
Images must be JPG, GIF, or PNG files.
- Command: S [number] [str-expd]
This command is used to set a status line. The line number is used only to
determine how lines should be sorted; for example, if there is a status line
10 and a status line 20, then the status line 10 should be displayed first,
regardless of which line was set first. If a text string is not supplied, it
removes the status line. If neither a text string nor a line number is
supplied, all status lines are removed.
Expressions stored within {}s are evaluated at the time the line is executed
and are not re-evaluated. Expressions stored within []s are re-evaluated
each time the status line is displayed.
- Example 1:
S 1 You have made [S:moves] moves so far.
- Example 2:
. You are in the middle of a four-way intersection. Each path leads to
a different city that you may explore. Where do you wish to go?
^ n Go north.
S 10 You are in the northern city.
g northcity
^ e Go east.
S 10 You are in the eastern city.
g eastcity
^ s Go south.
S 10 You are in the southern city.
g southcity
^ w Go west.
S 10 You are in the western city.
g westcity
- Example 3:
. Which of your friends would you like to take with you?
c has_friend1
* no_1 Leave Friend #1.
S 10
v has_friend1 = 0
C
* yes_1 Take Friend #1.
S 10 Friend #1 is with you.
v has_friend1 = 1
c has_friend2
* no_2 Leave Friend #2.
S 20
v has_friend2 = 0
C
* yes_2 Take Friend #2.
S 20 Friend #2 is with you.
v has_friend2 = 1
- Example 3:
* 1 Erase all status lines.
p Ok.
S
- Command: a (tag-exp)
Adds an object to the player's inventory, where (tag-exp) is an object tag.
If the player is already carrying the specified object, nothing happens.
- Command: d [tag-exp]
Drops an object from the player's inventory, where (tag-exp) is an object tag.
If the player doesn't have the specified object, nothing happens.
If (tag-exp) is omitted, all objects, regular and enumerated, are
dropped from the player's inventory. This usage differs from the
D command in that only the current inventory bag
is affected.
See also: the D command.
- Command: e (tag-exp) = (expr)
Command: e (tag-exp) (op) (expr)
This command is used to set or modify how many of enumerated object with
tag (tag-exp) the player is carrying. If an assignment operator
(=) is provided, the number of objects the player
is carrying is set to the value of the expression. Otherwise, the number
of objects is modified by the operator provided.
- Example 1:
* ap Take five apples.
e apples = 5
- Example 2:
* cr Take a crouton.
e croutons = e:croutons + 1
p Ok. You have {e:croutons} now.
- Example 3:
* cr Take a crouton.
e croutons + 1
p Ok. You have {e:croutons} now.
- Example 4:
* pick Pick a blade of grass.
p Ok. You pick up a blade of grass.
e grass + 1
c e:grass > 0
* drop Drop a blade of grass.
p Ok. You drop a blade of grass.
e grass - 1
- Example 5:
* buy Buy the harpoon from the shopkeeper.
c e:coins < 35
p You don't have enough money to buy the harpoon.
C
p You hand the shopkeeper 35 gold coins to buy the harpoon.
e coins - 35
a harpoon
- Example 6:
* take Double the number of fallen leaves you have.
e leaves * 2
- Command: D [tag-exp]
Drop all regular and enumerated items from the inventory bag [tag-exp]. If
[tag-exp] is omitted, all objects are dropped from all inventory bags.
The need for this command is rare, but it can help if the state of the
game needs to be reset. Note that if you're only using a single inventory
bag in your game, the d command (which drops all
items from the current inventory bag) works just as well.
- Example 1:
* bj Bungee jump off the cliff.
p You drop like a rock, the wind rushing at your face. When you
reach the end of the cord, you find that it doesn't stretch as much
as you would have liked; everything you are carrying lurches out of
your grasp and plummets to the valley floor below you.
D 0
- Example 2:
* win Win the game.
p You won! You start over at the beginning -- but this time, something
isn't quite as it was the first time through.
W
z
Z
D
v won_once = 1
g beginning
See also: the d command.
- Command: b (tag-exp)
Switch the current inventory bag to (tag-exp). Note that the default
inventory bag is "0". The visible effect of switching
inventory bags is that the player will appear to have lost all inventory items
and gained those items in the (tag-exp) bag, if any. But any items in the
first inventory bag remain present and are regained when a
b command is issued to switch back.
- Example 1:
* rush Rush past the guards.
p You try to rush past the guards, but they catch you, confiscate your
possessions, and lock you up.
b emptybag
- Example 2:
* escape Escape from prison.
p You bust out of jail when the guards aren't looking and recover your
possessions.
b 0
See also: the B command.
- Command: B (tag-exp)
Adds the contents of inventory bag (tag-exp) to the current inventory bag.
Note that the (tag-exp) inventory bag is NOT cleared of the items there, so
if they are no longer required, you should issue a
D (tag-exp) command immediately afterward.
See also: the b command.
- Command: s (var-exp) = (expr)
Command: s (var-exp) (op) (expr)
This command is used to set or modify a state variable for the current
location. If an assignment operator (=) is
provided, the state variable is set to the value of the expression.
Otherwise, the state variable is modified by the operator provided.
- Example 1:
s state = 15
s count = 0
- Example 2:
c time_left > 0
s time_left = time_left - 1
- Example 3:
c time_left > 0
s time_left - 1
- Example 4:
* bug Bug the old man to let you in his house.
s old_man + 1
c old_man < 3
p "Go away," the man snarls.
C
p "Ok! Ok! Enough already. Get inside." The old man
shoves you through the door.
s old_man = 0
g inhouse
Note: To maintain compatibility with older code, (var-expr)
is assumed to be "s" if it is missing. This use is deprecated and should not
be used in new Smash code.
- Deprecated Examples:
s = 15
s + 3
s - 5
s / 2
- Command: v (var-exp) = (expr)
Command: v (var-exp) (op) (expr)
This command is used to set or modify a global variable. If an assignment
operator (=) is provided, the global variable is
set to the value of the expression. Otherwise, the global variable is
modified by the operator provided.
- Example 1:
v var = 5
v ate_boulder = 1
- Example 2:
* 1 Talk to the old man.
v talked_to_old_man = .talked_to_old_man + 1
p You talk to the old man again.
You have talked to him {.talked_to_old_man} times.
- Example 3:
* 1 Talk to the old man.
v talked_to_old_man + 1
p You talk to the old man again.
You have talked to him {.talked_to_old_man} times.
- Example 4:
c light
* off Turn off the light.
p You turn the light off.
v light = 0
C
* on Turn on the light.
p You turn the light on.
v light = 1
Note: To maintain compatibility with older code, (var-expr) is
prepended with a "v" if it consists only of digits. For example, if (var-expr)
is "35", then "v35" is assumed. This use is deprecated and should not be used
in new Smash code.
- Command: t + (var-exp) = (expr)
Command: t - (var-exp) = (expr)
Command: t + (var-exp) (op) (expr)
Command: t - (var-exp) (op) (expr)
This command is used to set or modify a timer. If an assignment
operator (=) is provided, the timer is set to the
value of the expression. Otherwise, the timer is modified by the operator
provided. If there is a + symbol preceding (var-exp),
the timer should be made an upward counting timer; if there is a - symbol,
the timer should be made a downward counting timer.
- Example 1:
t + moves = 0
t - countdown = 10
- Example 2:
* 1 Talk to the fairy queen.
t - moves_left = 15
p The fairy queen says, "You must beat me at chess in fifteen moves."
c moves_left > 0
* 2 Plead with the fairy queen for more time.
# Note: We must increment by 6, not 5, because one
# move is wasted asking for the 5 extra moves.
t - moves_left + 6
p The fairy queen says, "Well, ok, I'll give you five additional moves."
- Command: t << (expr)
Command: t >> (expr)
Rewind (<<) or fast-forward (>>) all timers by the value of (expr).
Rewinding timers would mean incrementing downward counting timers and
decrementing upward counting timers. Vice versa for fast forwarding. These
commands can be used to make certain moves take more or less in-game time than
others. Note that normally timers advance one unit per move, so rewinding
timers by 1 effectively pauses timers for that turn.
- Command: z [lower-tag-exp]
Zeroes out (deletes) all state variables. If [lower-tag-exp] is present, only
zero that location's state variables. The need for this command is rare;
it is helpful in situations where you want to reset the state of the game.
Note this command, without an argument, deletes all state variables,
not just the state variables for the current location. If you want to delete
only the current location's state variables, you must specify the location by
name, although, for locations no longer than eight characters in length,
example 2 provides a shorthand way of accomplishing this without establishing a
dependency on the current location name.
Also note that global variables, timers, and inventory items remain
unchanged.
- Example 1:
* s Start the game over.
p You start over.
z
Z
g beginning
- Example 2:
* r Delete the state variables of the current location.
# Note: This only works if the current location is no longer than eight characters.
z {'S:loc}
See also: the Z command.
- Command: Z
Zeroes out (deletes) all global variables and timers. The need for this
command is rare; it is helpful in situations where you want to reset the
state of the game.
Note that state variables and inventory items remain unchanged.
- Example 1:
* s Start the game over.
p You start over.
z
Z
g beginning
- Example 2:
* win Win the game.
p You won! You start over at the beginning -- but this time, something
isn't quite as it was the first time through.
W
z
Z
D
v won_once = 1
g beginning
See also: the z command.
- Command: g (lower-tag-exp)
Specifies that the user should be moved to the location named (lower-tag-exp).
This command is only used inside option blocks, with one exception: a
g command must appear in the "start" file
outside any code blocks in order to specify where the user should start the
game.
Note that this command does not branch to the new location immediately but
rather sets where the user should be moved to next. What this means
is, code immediately following a g command will
still be executed. Note that examples 2 and 3 below are equivalent.
- Example 1:
^ n Go north.
g lake
- Example 2:
* leap Leap over the moving lava flow.
p You hurl yourself over the moving lava flow. It's hot!
g otherside
- Example 3:
* leap Leap over the moving lava flow.
g otherside
p You hurl yourself over the moving lava flow. It's hot!
- Command: G
Begins a block of code that should only be executed if the player has just
arrived at this location by a g command.
G blocks must be located outside functions and
option blocks. The intended use for G blocks is to
initialize any state variables you plan to use within the location.
Note that G blocks will execute if you
g to the location even when you're already there;
so a location that has a g command to itself will
force the G blocks to run again.
- Command: f (tag-exp2)
Command: f (lower-tag-exp1).(tag-exp2)
Executes the function named (tag-exp2), located in the file
(lower-tag-exp1).sma. If (lower-tag-exp1) is missing, the function is assumed
to reside in the current file. Note that if an unscoped state variable is
referred to in a function, it refers to a state variable belonging to the
player's current location, which is not necessarily the location where the
function itself resides. Basically, the location the player is in (and,
therefore, the set of state variables in use) never changes as a result of
calling a function in a different file.
Note that when a function is called via the f
command, as opposed to the f: operator, the
function return value can still be retrieved by checking the value of
S:return).
Normally, though, it is more readable and less error-prone to use the
f: operator and read the function return value
directly.
See also: the ~ and r commands.
- Command: ~ (tag)
Defines the function named (tag). It begins a code block containing the
code to execute when the function is called. If the state variable is
referred to in a function, the state variable for the location that the f
command is executed in is the one that is used.
- Example 1:
~ describe_area
. It is nice out.
c set_off_blast
, Except for the high radioactivity from the nuclear
blast you set off.
- Example 2:
~ examine_hat
c state_of_hat = 0
p Your hat is brand new.
C state_of_hat = 1
p Your hat is looking rumpled around the edges.
C state_of_hat = 2
p Your hat is ragged and stained.
C
p Your hat is a total wreck.
- Example 3:
~ add_suicide_option
* suic Kill yourself.
p You die, by your own hand. Not very smart, was it?
l
See also: the f and r commands.
- Command: r (expr)
Sets the function return value. The function return value is a numerical value
that gets set to 0 when a function is called and is set by the
r command. A function with no
r command, therefore, has a return value of 0.
The function return value is what the f: operator
evaluates to. It is also what S:return evaluates to.
Note that the r command does not cause the function
to return; it simply sets what the function return value is.
- Example 1:
~ generate_random_up_to_max_variable
r r:max
- Example 2:
~ get_damage_to_monster
c monster = 1
v hits = 10
C monster = 2
v hits = 30
C
v hits = 50
r hits + weapon - armor
p You hit the monster for {hits} damage!
v monster_hits = monster_hits - hits
Note that there is only one function return value, shared among all function
calls. It is therefore important not to set the function return value
prior to a function call, which would then overwrite the value. This problem
can be avoided simply by making the r command the
last command in a function. In the rare situation that this is not convenient,
just make sure the r command occurs after any
function calls.
- Incorrect Example 1:
~ function
r 5
p You have {f:get_number_of_fish} swordfish.
- Correct Example 1:
~ function
p You have {f:get_number_of_fish} swordfish.
r 5
- Incorrect Example 2:
~ function
r 5
f set_status_lines
- Correct Example 2:
~ function
f set_status_lines
r 5
With correct placement of r commands, it will be
perfectly safe to put function calls right on the r
line, as in the following example:
See also: the f and ~ commands.
- Command: c (expr)
Executes the following indented block of code only if (expr) evaluates to
a nonzero value.
- Example 1:
. You are in a room.
c opened_cabinet
, There is an open cabinet here.
c !took_doll
, There is a doll inside.
c rug = 1
, The rug has been lifted to reveal a trapdoor.
c rug = 2
, The rug has been torn from the nails that held it in place. There is
a trapdoor in the middle of the room.
- Example 2:
c a:torch , !torch_lit
* light Light the torch.
c d:matches
p You have nothing to light it with.
c a:matches
p You light the torch with the matches.
v torch_lit = 1
- Command: C [expr]
Executes the following indented block of code only if previous linked
c and C commands failed
and [expr], if present, evaluates to a nonzero value. The
C command can be thought of as an "else if" command.
- Example 1:
* 1 Examine the hat.
c state_of_hat = 0
p Your hat is brand new.
C state_of_hat = 1
p Your hat is looking rumpled around the edges.
C state_of_hat = 2
p Your hat is ragged and stained.
C
p Your hat is a total wreck.
- Example 2:
* 2 Fight the battle.
c a:sword
c a:shield
c a:shinguard
p You start to stab at your opponent, but he
swings first. The blow glances downward
off your shield and is deflected by your
shinguard. Then you spy an opening and
thrust your sword home. Your opponent
slumps to the ground.
v won_fight = 1
C
p You start to stab at your opponent, but he
swings first. The blow glances downward
off your shield and nicks your leg. Startled
by the sudden stinging, you are thrown off
your guard, and your opponent takes advantage
of your momentary weakness.
l
C
p You start to stab at your opponent, but he swings first.
With no way to block the blow, it strikes home,
and you die.
l
C
p Without a sword, you quickly lose.
l
- Command: L (expr)
Executes the following block of code repeatedly until (expr) evaluates to zero.
Caution! Be careful not to create an infinite loop, that is, a
situation where (expr) always evaluates to a nonzero value, so the block of
code just keeps executing and executing.
Loops are useful if you need to do something repeatedly. Usually you would
need to name variables or object tags with numbers to use loops effectively;
for example, if you had 100 items, named item_1 through item_100, a loop could
be used to add each one to your inventory, as shown in Example 2.
- Example 1:
. You hug and kiss your beloved five times:
v i = 0
L i < 5
, X O
v i + 1
- Example 2:
v i = 1
L i < 101
a item_{i}
v i + 1
- Example 3:
p You see a multiplication table on the wall. It looks like this:<p>
P <table>
v x = 1
L x <= 10
P <tr>
v y = 1
L y <= 10
P <td>{x*y}</td>
v y + 1
P </tr>
v x + 1
P </table>
- Command: R (expr)
Executes the following block of code once without initially evaluating
(expr), then loops back and thereafter treats the R
command like an L command, where the code block is
executed repeatedly until (expr) evaluates to zero. This is functionality
equivalent to a "do/while" loop found in other programming languages.
Caution! Be careful not to create an infinite loop, that is, a
situation where (expr) always evaluates to a nonzero value, so the block of
code just keeps executing and executing.
Normally, you will want to loop using the L command,
but the R command can be useful if you find yourself
writing code just before a loop, then repeating that code inside the loop.
For example, this code:
v random_number = r:10
L random_number = 3
v random_number = r:10
...picks a random number between 0 and 9 that is not 3. A number from 0 to 9
is chosen, and if it is 3, another random number is chosen instead. The
drawback to this algorithm is that the line of code that stores the random
number is repeated. Instead, the following functionally-equivalent code can
be used instead:
R random_number = 3
v random_number = r:10
It does not matter if the 'random_number' variable was previously defined or
not, or, if so, what it was set to. The loop will always execute at least
once, and so the 'random_number' variable will be set to a fresh random
number before the random_number = 3 condition is
ever evaluated.
- Example 1:
* pick Pick a random number from 0-99 not divisible by 3 or 7.
R !(r % 3) | !(r % 7)
v r = r:100
p Ok! How about the number {r}?
- Example 2:
* hunt Hunt around.
# Check to see if the player is missing any of items 0-99.
# If so, you find a randomly selected item. If not, you don't find anything.
v missing_an_item = 0
v i = 0
L i < 100
c d:item_{i}
v missing_an_item = 1
v i = 100
v i + 1
c missing_an_item
R a:item_{i}
v i = r:100
a item_{i}
p You hunt around and find Item #{i}! You pick it up.
C
p You hunt around but don't find anything.
- Command: l
Specifies that the player should lose the game. Note that this command does
not branch to the "lose game" sequence immediately but rather sets
that the "lose game" sequence should commence once control flow terminates
naturally. What this means is, code immediately following a
l command will be executed. Note that the two
examples given below are equivalent.
One other thing to note. When a move is made that causes the player to lose
the game with a l command, the player's saved game
is not updated. That means that once the player reaches the "lose"
screen, then hits "undo" to undo the move, no changes made during
that move (for example, the setting of global variables) will be remembered.
- Command: w [str-exp]
Specifies that the player should win the game. Note that this command does
not branch to the "win game" sequence immediately but rather sets
that the "win game" sequence should commence once control flow terminates
naturally. What this means is, code immediately following a
w command will still be executed. Note
that Examples 1 and 2 are equivalent.
If the Hall of Fame for the game has no extra game-defined parameters (in the
game.txt file), then no [str-exp] argument should be present.
Otherwise, there must be a [str-exp] argument, which must consist
of a |-delimited set of string values that indicate what should be supplied
in each game-defined Hall of Fame field. Example 3 shows a win command for
a game with one extra "points" parameter. Example 4 shows a win command for
a game with three extra parameters: points, bonuses, and rank.
- Example 3:
* win Win the game.
p You won!
w {points}
- Example 4:
* win Win the game.
p You won!
c rank = 6
w {points}|{bonuses}|General
C rank = 5
w {points}|{bonuses}|Colonel
C rank = 4
w {points}|{bonuses}|Major
C rank = 3
w {points}|{bonuses}|Captain
C rank = 2
w {points}|{bonuses}|Lieutenant
C rank = 1
w {points}|{bonuses}|Sergeant
C
w {points}|{bonuses}|Private
See also: the W command.
- Command: W [str-exp]
Same as the w command, except that after the "win
game" message comes up and the Hall of Fame entry is supplied, the game does
not terminate but rather lets the player continue playing. It is extremely
rare that a game would ever use this command. One exception might be if the
game developer wanted to allow the user to be able play through the game a
second time with certain secrets unlocked as a reward for finishing the first
time. In such cases, the z,
Z, and/or D commands
may also be helpful.
Great care must be taken not to code a game with a W
command in such a way that a player can trivially enter many Hall of Fame
entries.
- Example 1:
* win Win the game.
p You won! You start over at the beginning -- but this time, something
isn't quite as it was the first time through.
W
z
Z
D
v won_once = 1
g beginning
- Example 2:
* win Win the game.
p You won! You start over at the beginning -- but this time, something
isn't quite as it was the first time through.
W {points}
z
Z
D
v won_once = 1
g beginning
- Command: ^ (tag) (str-exp)
Adds a new move option called (tag) and having the text (str-exp). Note that
(tag) is not displayed or referred to anywhere else; it must exist simply to
distinguish itself from other ^ options. The tag must be different from the
tags of all other ^ options displayed at the same time, as well as different
from any other ^ tag in the same file. (It may, however, reuse
a tag used by a @ option, * option, object, or function.
The ^ command is followed by a block of code (which
can legally but probably not practically be empty) that will be executed if
and when the player selects this option.
- Command: * (tag) (str-exp)
Adds a new action option called (tag) and having the text (str-exp). Note that
(tag) is not displayed or referred to anywhere else; it must exist simply to
distinguish itself from other * options. The tag must be different from the
tags of all other * options displayed at the same time, as well as different
from any other * tag in the same file. (It may, however, reuse a tag used by
a @ option, ^ option, object, or function.)
The * command is followed by a block of code (which
can legally but probably not practically be empty) that will be executed if
and when the player selects this option.
- Example 1:
* t Talk to the geezer.
p The geezer just wheezes and calls you a "young whippersnapper."
- Example 2:
c light_is_on
* off Flip the lightswitch.
v light_is_on = 0
p Ok. The light is off.
C
* on Flip the lightswitch.
v light_is_on = 1
p Ok. The light is on.
- Command: @ (tag) (str-exp)
If this command is issued in copts.sma, it defines a
new constant option called (tag) and having the text (str-exp). Note that
(tag) is not displayed or referred to anywhere else; it must exist simply to
distinguish itself from other @ options. The tag must be different from the
tags of all other @ options displayed at the same time, as well as different
from any other @ tag in the same file. (It may, however, reuse a tag used by
a ^ option, * option, object, or function.
When used in copts.sma, the @ command is followed by
a block of code (which can legally but probably not practically be empty) that
will be executed if and when the player selects this option.
If the @ command is given outside the copts.sma, it
may not be followed by a code block, and all it does is reassign the text
associated with the option. For example, some constant option might have the
text "Look at the broken sword." until some point in the game where you find
a blacksmith who can fix the sword, at which point the text becomes, "Look
at the reforged sword."
- Example 1: (in the copts.sma file)
@ sword Look at the broken sword.
p The silvery metal gleams in the light.
- Example 2: (in some other .sma file)
* 1 Ask the blacksmith to reforge the sword.
p The blacksmith agrees. It is fixed!
@ sword Look at the reforged sword.
v sword_fixed = 1
- Command: @ + [tag]
Command: @ - [tag]
With +, make the constant option [tag] visible and
available to the user; if [tag] is omitted, this is done for all constant
options. With -, make the constant option [tag]
invisible and unavailable to the user; if [tag] is omitted, this is done for
all constant options.
- Example 1:
c a:sword
* d Drop the sword.
p You drop the sword on the ground.
@ - sword
c d:sword
* t Take the sword.
p You take the sword.
@ + sword
- Example 2:
@ -
* w Wake up.
p Groggily, you open your eyes and look around. Now that you're awake,
you can do other things besides just wake up.
@ +
g awake
- Command: x (expr)
Set the random number seed. Normally, this is not necessary, because Smash
seeds the random number generator itself. However, this can be useful for
causing random number sequences to repeat. Although the seed can be any
numerical value, normally it is set to some previous value of
S:rseed, which returns the current random number
seed.
In the above example, every time you select option 3, you'll get a different
set of random numbers. However, if you select option 1, then option 3, you'll
get the same set of random numbers as you'll get if you subsequently select
option 2, then option 3 again.
The effect lasts across multiple turns, too. If you select option 1, then
option 3 three times, you'll get the same twelve numbers as you will if you
subsequently select option 2, then option 3 three times.
- Command: ! [text]
Throw an error. This command would not be used in a complete game, but it
is a helpful debugging tool during game development.
- Example 1:
. You are in a room.
c have_sword = 1
, You have a sword.
C have_sword = 0
, There is a sword on the floor.
C
! The value of "have_sword" was {have_sword}, an
unexpected value.
|
|