I am a complete coding beginner and have spent some time searching the archives but I can't seem to find an answer. I'm using Harlowe and trying to write a passage that loops for a fixed number of times before changing. So, 'add sugar' for up to four times and then go to the passage "sweet enough already" on the fourth click.
I've got the loop to work ok but I have no idea how to count the number of loops and change the result based on said count. I'd be grateful for any pointers, and am keen to understand how things work rather than just copying and pasting!
Many thanks
Comments
In JavaScript, a simple loop will often look like this: Which, in plain English, means: So all we need to do is take that logic of the loop above and translate into passages.
First, we have our passage where we initialize the variable with how many lumps of sugar we have (none) and provide a link to a passage where the 'loop part of the loop' is going to take place: Then, we have a second passage which we're going to visit a couple times. Each time it increments the amount of sugar we have, then displays two options for text. If we have less than four lumps of sugar, we give the player a link to re-visit this passage—which is the same as repeating our loop. I also included a link for any weirdos who don't want extra-sweet coffee.
If we have four lumps (or more), we no longer have the option to re-visit the passage—which is analogous to saying "don't loop any more". (by the way, if you wanted the incrementing to happen upon clicking the link rather than visiting the passage, there's a pattern for making setter links in Harlowe)
I hope this helps and is what you're looking for. It's often helpful to see the code being asked about when answering a code question, so if this isn't quite the right answer, please post the text you tried.