It looks like you're new here. If you want to get involved, click one of these buttons!
But I can't understand how to phrase else-if and things like that. Sorry if this isn't clear enough. Can someone just... Hold my hand and explain plainly how to use a dang variable. How to use else-if and either and the other things.(if: $legs is 8)[You're a spider!] will show the You're a spider! hook if $legs is 8. Otherwise, it is not run.
Comments
However, I will persist and tell you how I do it.
I create a passage called StoryInit, add any variable I'm going to use in there, and set them to false. For instance:
Then in the passage where the variable is used I would say:
1. Syntax
In brief, variables are basically placeholders for a value. This value can be either a number, like 1, or a string, like "hat".
All variables are called in your code by a string of characters beginning with $. $legs, $name, $have_sword? are all examples of a variable.
Note that until you use the (set:) macro to define the value of a variable, it has the value 0 by default. If we enter "$name" in a blank passage, until we define it, it'll just print "0". After you define it, you can use your variable in passage text as a placeholder for the value it contains.
2. The (set:) macro
Used for setting the contents of variables!
Setting a variable to a number or a string:
Incrementing the value of a variable:
Setting the value of one variable to the value of another value:
3. The (if:) macro
Slightly more complex. (if:) checks to see if the condition you put inside it is true or not. This is done with these logical operators. Then, if the condition you gave it is true, it displays/does whatever you put in brackets next to it. Here're some examples:
As you can see in the last example, besides displaying text in the brackets, we can also nest additional macros inside of the first.
4. The (elseif:) and (else:) macros
(elseif:) can perhaps be more clearly read as "otherwise-if." It's very similar to (if:), but with one additional caveat: unlike (if:), which only cares whether or not its condition is true, (elseif:) goes up against the brackets of a previous (if:) or (elseif:), and also checks to see if it that one was true or not.
Say we want to expand on our earlier arrow-shooting example-- an (elseif:) will let us tell the game what to do if we're out of arrows.
(else:) is very similar to (elseif:), but it doesn't check for its own condition. It can be read as "otherwise". It's usually used at the very end of a list of checks using (if:) and (elseif:) as sort of a "none of the above" condition.
5. The (either:) macro
Compared to the previous macros, this one's really easy-- I'll just quote the Neocities documentation: Nore that you can also use it inside other macros, like (set:), to generate random values that you can then save long-term, like so: All of the values have an equal chance of being picked.
Hope this helps-- and if I can help to further clarify my wall of text here, just ask!
I've attached a simple working example of several of the (if:)/(elseif:)/(else:) macros in use-- just right-click the attachment and hit "save as" to download it. Then you can import it in Twine and play around with the code.