Hi!
I'm making a game with Harlowe and I want to make it so the player does not have the option to select the same item multiple times Do this I thought this code would work.
(set:$choicesandal to 0)
(if: $choicesandal is 0)
Add Sandal to Stew
(if: $choicesandal is not 0)
Look at North Wall
However every time I test the game both choices print despite the second "if" condition not being fulfilled.
If they click
Add Sandal to Stew
You added the sandal to the stew.
(set: $choicesandal to $choicesandal+1)
(set: $stewchoice to $stewchoice+1)
Any help would be super appreciated!
Comments
I suggest that use a boolean (true / false) instead of a number to track if something has happened or not:
The following two examples are the same, the only differences is that one is testing for the $variable being true, the other false: ... to indicate that the Sandal has been added to the Stew change $hasSandal to true:
You don't need a Add Sandal to Stew passage, the whole lot can be done in a single passage using a named-hook combined with both a (link:) and (replace:) macro:
I have modified the code to this
However now it is starting the hook before I even click the choice. In fact the choice isn't even clickable. Am I using improper syntax?
Your example will always show the Add Sandal to Stew link every time the passage is displayed even if the Reader has already done that action, and based on your example you may not need both the $addSandal and $hasSandal variables.
Generally it is a good idea to initialize (give a default value) to all your $variable at the start of your story, Harlowe 1.1.1 has a new feature which helps you do this. You create a new passage (I would name it Initialize), assign it a tag of startup and any code you place in this passage will be run before the story starts.
A possible example of a startup tagged passage for your story: