User Tools

Site Tools


variable

This is an old revision of the document!


Variables

Expressions by themselves aren't much use to your stories. Unless you're writing a mathematical thriller, you probably don't need to evaluate 2 + 2 too often. Where they do come in handy, however, is when variables enter the picture.

A variable is a place to store a value so that you can remember it later. You can store both strings and numbers in variables. The variable $name might contain the main character's name, “Agatha Christie”, or the variable $money might contain the amount of money Agatha has in her pocket – the number 15.75.

Variable names

Variables have a few restrictions on their names. They must start with a $ sign. That's called a sigil — it tells the computer that what's coming next is a variable, not a number or string.

After the initial $ sign, a variable name can begin with a letter, either uppercase or lowercase, or an underscore _. After the first letter, you can have any combination of letters, numbers, or underscores. Punctuation and spaces aren't allowed anywhere.

Here are some legitimate variable names:

$housesDestroyed
$_my_favorite_color
$AN_EXTREMELY_IMPORTANT_NUMBER
$street8
$i

Some bad variable names:

$what was it called
$Idon'tRemember
$3.95
$8thSurprise
$$$make_money_fast$$$

To manipulate variables, see the articles for the <<set>> macro and the <<remember>> macro, as well as the link syntax.

variable.1387328877.txt.gz · Last modified: 2017/10/09 20:38 (external edit)