Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sugarcube: Can Click Function Stop at Certain Numbers

Using plus and minus in Twine sugarcube with the click function, is there a way to stop the variable from being adjusted if it hits a certain limit? For example, if you had the variable strength and the player could add/subtract points to it, is there a way that you could keep it from going below three or above eighteen (to use old D&D numbers)?

Basically I want to keep the variable limited to a certain range. I have a crude work around in place for my current project (if the player tries to continue with a number outside the available range instead of continuing the story it just pops up a message telling the player what is wrong and to go back and do it again) but I'm wondering if there is a clearer way to do it where clicking on the plus/minus doesn't yield anything if it would take the number outside the designated range.

Comments

  • edited October 2015
    I believe you can simply use an <<if>> statement.

    For example:
    <<click "[+]">>
    <<if $Strength < 18>>
    <<set $Strength++>>
    <<endif>>
    <</click>>

    Or you could wrap the entire <<click>> macro in the <<if>> statement, so it only appears if the player actually can use it.
    <<if $Strength < 18>>
    <<click "[+]">>
    <<set $Strength++>>
    <</click>>
    <<endif>>
  • You may want to read this thread as it is about a similar issue and the solutions should also work for you.

    note: TheMadExile has suggested replacing each of the <<run>> macro calls in my solution with script elements instead because they would be more efficient. (And he should know as he is the developer of SugarCube! lol)

    Example of reformatting a <<run>> macro: from => to
    <<run $("#stats-str-plus button").prop("disabled", false);>>
    
    would become:
    
    <script>$("#stats-str-plus button").prop("disabled", false);</script>
    
Sign In or Register to comment.