User Tools

Site Tools



This shows you the differences between two versions of the page.

Link to this comparison view

twine1:variable [2017/10/09 20:39] (current)
Line 1: Line 1:
 +===== Variables =====
 +[[Expression]]s by themselves aren't particularly powerful. [[Function]]s like previous(), either() and visited() can help in making [[link]]s, [[<<​print>>​]] and [[<<​if>>​]] macros more interesting,​ but if you want anything more complex than those, **variables** will be necessary.
 +A variable is a place to store a value so that you can remember it later. You can store strings, booleans 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:
 +Some bad variable names:
 +$what was it called
 +To manipulate variables, see the articles for the [[<<​set>>​]] macro and the [[<<​remember>>​]] macro, as well as the [[link]] syntax.
twine1/variable.txt · Last modified: 2017/10/09 20:39 (external edit)