Hello,
I am on last 2.0 and Harlowe.
For a passage, I would like the user to be able to decrease a number by clicking it (or clicking some other word), and do something when it reaches 0.
Say, the user has 10 chips and I want him/her to eat them, one by one, and show the remaining chips every time the user eats one.
So I was trying something like:
(set: $chips to 10)
There are still (link: "$chips")[(set: $chips to it -1)] chips left
... so when the number is clicked, the variable decreases by one. The problem is that I want the clicked number to show chips left after each bite. And so, idiotic recursive nesting problem arises, i.e:
(set: $chips to 10)
There are still (link: "$chips")[(set: $chips to it -1)(link: "$chips")[(set: $chips to it -1)]] chips left
... with that code, the user can click the "10", then a "9" appears in its place. But to be able to reach 0, I should nest that 9 more times within itself! crazy
Is there any other way you would reccomend this to be done?
I assume I could (link:) another word, use it to decrease the $chips variable, then use a (live:) somehow to constantly check, and display the updated variable ?
Any help is greatly appreciated
Comments
Thanks again.
You can do what you want with two variables, a hook, and a (live:) macro: Code breakdown:
1. The amount hook:
We use a hook so we can replace its contents with a new copy of the (link:) macro each time the link is clicked. 2. The (live:) macro:
We check every 1/50th of a second to first see if all the chips are gone, if they are we display a zero and stop the (live:) macro, otherwise we check the $selected variable to see if the links was clicked. If it was clicked we reset the hooks contents so it contains the (link:) macro again and reset the $selected variable. You may want to change how often the (live:) macro runs by making the 20ms a large value.