Saturday, 1 March 2014

Using visited and visitedTag

These two functions, visited and visitedTag, are very useful for maintaining state with a minimum of effort. Twine remembers every page the player has visited, and so you can check where she has been previously. Let us suppose there was an option to go to a page "Get the big sword", and some time later, the player is encountering a monster. We might do this:

<<if visited("Get the big sword") >>
You stand your ground, branishing the big sword you found earlier. Intimidated, the goblin runs away, allowing you to [[explore more]]
The goblin leaps at you, tearing you apart with his dirty claws. As you llie dying, you wonder if there was any way you could have found a weapon.


Note that the link appears inside the conditional text.

It is important to type this accurately. This will fail:

<<if visited("get the big sword") >>

You need to get the page name exactly right. Also, there must be no spaces before "if", or either side of "else" and "endif".

The visitedTag function is similar, but checks if the player has visited pages with the given tag. This is useful if the game should check if the player has visited any one of a set of pages. Perhaps there are three places the player could get that big sword, and you want to check if she hasd been to any of them. there might be an number of passages in which the player gets injured, and you want to check if she has been to them. here is an example (note that tags cannot have spaces):

<<if visitedTag("bigsword") >>

Unfortunately, Sugarcube does not support visitedTag.

ETA: The day after I say  Sugarcube does not support visitedTag, it gets added to Sugarcube. Hurray!

No comments:

Post a Comment