Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

A Tutorial To Twine Macros: If, Set, and Click [FOR TWINE 2.0] (Harlowe)

edited April 2015 in Chit-Chat
An Tutorial To Twine Macros: If, Set, and Click
Many people have wondered how to use these macros. Well, I will show you.
1: Understanding Macros
If you don't know what a macro is, it is a tiny tweak you can add to your stories to make them more interactive.
Some macros keep track of variables (like how many bats you killed), some make things appear when you click random things (like a hidden click that continues to the next passage), and some even wonder IF that variable is equal to something (like if the number of bats you killed is greater than 5). Macros are very useful.
But, we are here to learn how to use them.
1: If - The Macro That Believes
The 'if' macro is very useful for comparing variables.
Let's say you wanted to see if the variable $batsincave was equal to 5.
Then, you would type this in:
(if: $batsincave is 5)[

Now, did you notice the extra [ I put at the end?
That bracket shows what will happen if $batsincave is 5.
You could put anything after that bracket.
But you have to close it with a closed bracket. ]
For example:
(if: $batsincave is 5)[
There are 5 bats. ]

In that case, it would say 'There are 5 bats." only and only if the number of bats if 5.
Pretty neat, huh?
But what if you wanted to make something else happen if it wasn't 5, instead of doing nothing.
If we wanted it to say 'There are not 5 bats.' if there aren't 5 bats, we would do this.

(set: $bats5 to false)
(if: $batsincave is 5)[
(set: $bats5 to true)
(if: $bats5 is true)[
There are 5 bats.
(if: $bats5 is false)[
There are not 5 bats.

So, we used the SET macro to set a variable if the number was 5, and the rest checks the variable.
Notice how we set it to false first, so if it did not set it to true (by having 5 bats) it would be false,
and then the other sensor would tell us (There are not 5 bats.)
More advanced 'if' tutorials will be in part 2.
This brings us to our next macro.

2: Ready, SET, Go!
The set macro is used to set a variable.
For example if you wanted to set $teapot to 1:
(set: $teapot to 1)
That says, "Hey! We should set $teapot to 1!"
The set variable is pretty easy to understand.
For example:
(set: $variable to 3)
Very easy.
For more advanced set tutorials, please wait for part 2.

3: To Click, or not to Click?
The click macro makes something happen when you click something.
First you have to put the thing to click (let's call it a clicker):
What that did is make a link called exampleClick that performs the function Example.
The link is in the brackets, and the function is inside the < and |.
Now, where is the function?

(click: ?Example)[
You clicked exampleClick.

That's the function.
So now, if you click exampleClick, it will perform the function Example.
Pretty neat.

That's all. Be sure to wait for part 2!


  • well done, though you may want to change your thread title to indication that this tutorial is for the Harlowe story format only because those examples wont work in the other two story formats. :)
Sign In or Register to comment.