Hey, I am using the default mode for Twine and would like to make bombs, but I dont know how two make the following thing: Someone has to click on my custom button, then a variable is counted down and you can enter a new field OR, if the variable is already 0,it should say something like"you will have to buy a bomb!"Can someone help me with an idea? Iam not that experienced with JavaScript jet sadly.
Comments
I highly recommend checking out the Harlowe documentation if you haven't already done so!
Also: if you're using Twine 1, you still shouldn't need to use any JavaScript to do this. I'm not familiar with Twine 1 syntax, however.
I think what you want is the following:
[list type=decimal]
A passage that contains a "yes" and a "no" link.
When clicking "no", the user goes to the "no" passage. Normal Twine stuff, right?
When clicking "yes", Twine checks to see if the counter variable is 0.
If the counter variable is 0, Twine sends them to a passage or displays text that says something like "Sorry, you don't have any bombs"
If the counter variable is greater than 0, Twine sends them to a passage that says something like "you used a bomb" and decrements the counter variable by 1.
If that's correct, InspectorCaracal's example code actually does that, you just have to change "[[Go make the bomb]]" and "Sorry! You'll have to buy a bomb!" to whatever text or links you want.
The following is a modified version of @InspectorCaracal's solution changed to be based on the example in your HTML file.
note: the (set: $bombs to 0) line is only need to test the code, change it to (set: $bombs to 1) to see what happens when you have a bomb. Here is copy of the above (click:) macro formatted so it is easier to read, and to see that is happening: One thing you may of noticed is that if you click the Yes link when you have no bombs the No link is still clickable, the following code contains a fix for that: Again here is copy of the above (click:) macro formatted so it is easier to read, and to see that is happening: The difference is the (replace:) macro, which being used to remove the unwanted No link.