Hi there! I'm a teacher trying to teach Twine with a bunch of enthusiastic primary-aged writers. They want to know how to do all kinds of things and I am doing my best to stay one step ahead of them. At the moment I am trying to figure out how I can keep count of something, like the number of keys collected.
At the moment I have (if: $key is 3) as a conditional to show the text that allows the reader to open the door. I have (set: $key is '0') and the beginning of my story.
What do I use to increase the count of $key by a given value? Something like (set: $key +1)?
Sorry if this question has been asked and answered elsewhere. I didn't exactly know what to search for. Thanks for your assistance!
Comments
There are different primitive (Javascript) data types which can be used for values in any of the story formats, in your example you are assigning a String representation of the number zero instead of an actual numeric representation.
You are also using the wrong operator (is) to do an assignment, the Example usage section of the (set: ) macro documentation shows it using the to operator.
After changing both the data type and operator your initialisation example would look like the following. ... notice the lack of single/double quotes and the replacement of is with to, once you make those changes you will be able use the value stored in $key as a number.
The Details: section of the (set: ) macro documentation includes two examples of how to increment the current value stored within a variable by one.
http://www.motoslave.net/sugarcube/2/docs/macros.html#macros-link
and do the example provided at the end. It shows how to count things.