# The game doesn't stop counting at 100% like I need it to.

I'm making a very tiny prototype game for a course i'm on and have been given a small task to get used to Twine as I've never done any coding or anything before.

The idea is that I need to get the player to finish their homework using percents to show how far along they are, these percents can go up by 10, 20 or 30 each time you click the action. So you get a page that says :

[You're only at \$percent%, keep going! [[Keep going->Do homework]] OR [[Give up]] ]

This system works fine but *SOMETIMES* when it gets to 100% it won't stop counting and goes to like 110%+ even though I've put text in place to stop it at 100. How can I get it to stop counting at 100 every time? :)

The entire text is this:

(if: (either: 0, 1) is 0) [
You're doing your work and typing as fast as you can.
(set: \$percent to \$percent + (either: 0, 20, 30))
(if: \$percent < 1) [You've been typing so fast and not paying enough attention that what you have is nothing but mindless babble, you have to [[Give up]] otherwise you'll be way too late]
(else:) [
(if: \$percent < 40) [It's about \$percent% done. You're working hard and making progress, it's certainly not the best it could be but you can [[Keep going->Do homework]] OR [[Give up]]]
(else:) [Already at \$percent% done. You're doing incredibly, you can't believe how fast your doing this homework. It all makes sense too! [[Keep going->Do homework]] OR [[Slack off abit]] ]
]
]

(else:) [
You figured a bit more of your homework out!
(set: \$percent to \$percent + (either: 10, 20, 30))
(if: \$percent >= 100) [[[You've finished your work!]]]
(else:) [You're only at \$percent%, keep going!
[[Keep going->Do homework]] OR [[Give up]] ]
(else:) [So close! You're \$percent% done.
[[Keep going->Do homework]] OR [[Give up]] ]
]

by (159k points)

Please use the Question Tags to state the name and full version number of the Story Format you are using, as answers can vary based on that informantion. Based on the syntax of your example I will assume you are using Harlowe, I will also assume you are using Harlowe v2.1.0 because it is the current latested released version.

Please use the Insert Code Snippet button in the comment area toolbar when including code examples in your questions & comments.

If you reformat your code to include indentation like so...

``````(if: (either: 0, 1) is 0) [
You're doing your work and typing as fast as you can.
(set: \$percent to \$percent + (either: 0, 20, 30))
(if: \$percent < 1) [\
You've been typing so fast and not paying enough attention that what you have is nothing but mindless babble, you have to [[Give up]] otherwise you'll be way too late\
]\
(else:) [\
(if: \$percent < 40) [\
It's about \$percent% done. You're working hard and making progress, it's certainly not the best it could be but you can [[Keep going->Do homework]] OR [[Give up]]\
]\
(else:) [\
Already at \$percent% done. You're doing incredibly, you can't believe how fast your doing this homework. It all makes sense too! [[Keep going->Do homework]] OR [[Slack off abit]]\
]\
]\
]\
(else:) [\
You figured a bit more of your homework out!
(set: \$percent to \$percent + (either: 10, 20, 30))
(if: \$percent >= 100) [\
]\
(else:) [\
You're only at \$percent%, keep going!
[[Keep going->Do homework]] OR [[Give up]]\
]\
(else:) [\
So close! You're \$percent% done.
[[Keep going->Do homework]] OR [[Give up]]\
]\
]``````

... you will notice that you have two (else:) macros with your last (if:) macro call which is invalid syntax.
eg. the  (if: \$percent >= 100) macro call has an invalid second (else:) associated with it. This is what is causing you to see the "So close! You're 110% done." type message.

I am assuming you want that section of code to either:

a. Randomly show one of the two (else:) related messages.

In which case you can replace both of those (else:) macros with the folllow (else:) macro which uses a (random:) macro to determine which message to show with the links.

``````(else:) [\
(if: (random: 1) is 1)[\
You're only at \$percent%, keep going!
]\
(else:)[\
So close! You're \$percent% done.
]
[[Keep going->Do homework]] OR [[Give up]]\
]\
``````

b. Show the "So close! You're \$percent% done." message when the \$percentage is close to 100.

In which case you can replace both of those (else:) macros with the folllow (else:) macro.

``````(else:)[\
(if: \$percent >= 80) [\
So close! You're \$percent% done.
]\
(else:)[\
You're only at \$percent%, keep going!
]\
[[Keep going->Do homework]] OR [[Give up]]\
]\
``````

note: I could of replaced the original two (else:) macros with something like the following example instead which uses an (else-if:) macro however that would of required having two instances ot the same set of Markup links, which is redundent.

``````(else-if: \$percent >= 80)[\
So close! You're \$percent% done.
[[Keep going->Do homework]] OR [[Give up]]\
]\
(else:)[\
You're only at \$percent%, keep going!
[[Keep going->Do homework]] OR [[Give up]]\
]\``````

There are a number of other logic, syntax or potential issues with your code:

1. Invalid space characters between the macro call and its associated hook.

You sometimes place a space character between the close parentheses ")" of the macro and the open square bracket "[" of it's associated hook, and while the Harlowe TwineScript parser has been changed to automatically fix this invalid syntax it would be better if you didn't do that.

``````<!-- GOOD SYNTAX with no space character. -->
(if: (either: 0, 1) is 0)[...]

<!-- BAD SYNTAX with invalid space character. -->
(if: (either: 0, 1) is 0) [...]
``````

2. Using the (either:) macro in a situtation when you should of used the (random:) macro.

The  (either:) macro internally uses a randomly generated number to determine which of the items passed to the macro will be selected. As your (if: (either: 0, 1) is 0) code line wants a random number between zero and one to be generated it makes more sense to use the (random:) macro instead.

``(if: (random: 1) is 0)[...]``

3. Using the (set:) macro's it operator when incrementing / decrementing a variable.

Your (set: \$percent to \$percent + (either: 0, 20, 30)) code line could be rewritten like so, which reduces the amount of typing you need to do as well as the chance of mispelling the variable name.

``(set: \$percent to it + (either: 0, 20, 30))``

4. Using punctuation characters within Passage Names.

Depending on the circumstances issues can arise if there are punctuation characters within a Passage Name, because some of those characters can have special meaning in web-based programming, and this is why it is generally recommend you not use them.,
I suggest changing the name your "You've finished your work!" Passage like so.

``[[You've finished your work!->Finished homework]]``

5. Using indentation, line-breaks, and Escaped line breakCollapsing whitespace markup.

This can help make your code easier to read, which can help make it easier to see potential issues.

After applying all of the above your original example would look something like the following..

``````(if: (random: 1) is 0)[
You're doing your work and typing as fast as you can.
(set: \$percent to it + (either: 0, 20, 30))
(if: \$percent < 1)[\
You've been typing so fast and not paying enough attention that what you have is nothing but mindless babble, you have to [[Give up]] otherwise you'll be way too late\
]\
(else:)[\
(if: \$percent < 40)[\
It's about \$percent% done. You're working hard and making progress, it's certainly not the best it could be but you can [[Keep going->Do homework]] OR [[Give up]]\
]\
(else:)[\
Already at \$percent% done. You're doing incredibly, you can't believe how fast your doing this homework. It all makes sense too! [[Keep going->Do homework]] OR [[Slack off abit]]\
]\
]\
]\
(else:)[\
You figured a bit more of your homework out!
(set: \$percent to it + (either: 10, 20, 30))
(if: \$percent >= 100) [\