Howdy, Stranger!

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

Setting a "max number" for variables.

Hi. Sporadic searcher, first time poster.

Ok, so I'm working on a board game with Twine 2 (Harlowe 1.1.1... I should probably update, shouldn't I?). Through "die rolls", the player needs to make it to the end of the board (Square 100). This is what I currently have in place to propel the player up the board:

(set: $event to (random: 1, 6))(if: $event is 1)[1! (set: $Player1 to $Player1+1)You're moving to Square $Player1.](if: $event is 2)[2! (set: $Player1 to $Player1+2)You're moving to Square $Player1.](if: $event is 3)[3! (set: $Player1 to $Player1+3)You're moving to Square $Player1.](if: $event is 4)[4! (set: $Player1 to $Player1+4)You're moving to Square $Player1.](if: $event is 5)[5! (set: $Player1 to $Player1+5)You're moving to Square $Player1.](if: $event is 6)[6! (set: $Player1 to $Player1+6)You're moving to Square $Player1.]

This all works fine, except for one little aesthetics problem. The user can currently get a result higher than 100, whereas I'd like to make it so that 100 is the max result. What do I need to add to make that so?

Thanks!

Comments

  • edited January 2017
    Instead of all that code, why not something like:
    (set: $event to (random: 1, 6))
    (set: $player1 to $player1 + $event)
    (if: $player1 >= 100)[(set: $player1 to 100)]
    (print: $event)! You're moving to Square (print: $player1).
    

    Edit: The (if) statement in the middle will keep the variable from going over 100.
  • Yes, I could definitely practice being more concise with my code. There's a few variables that'll need testing, but at first glance, seems like this works perfectly. Thanks!
Sign In or Register to comment.