Howdy, Stranger!

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

If/Else and modifiers

Hi there,

I'm very new to twine and am currently just playing around to see what kind of functionality I can get out of it. I've run into a bit of a roadblock and was wondering if a more experienced user could help me out. Apologies in advance for how wordy this will be, but I want to be as clear as I can.

I am running Twine 2.0 in default format, I think that's harlowe.

So basically what I want to do is when I pick an option have a dice roll occur, lets say 1d6 and then add a pre-determined modifier to that number to make a total, then use that total to determine if whatever you are trying to do is successful. Much like in a tabletop game where you would roll to hit an opponent.

At the start of the test story I have an option to pick what "class" the player is and this determines their base stats, so for example if they pick "warrior" then (set: $strength to 5) occurs, going forward their strength is 5.

Then they encounter a bandit or something and you have the option to "attack the bandit" I want this to make a dice roll occur, then add their strength to the roll to make a total which determines their success. So lets say the threshhold for success is a 10 - they need to roll at least a 5.

This is where I am stuck, I don't really know what the formula for something like this should look like, I've tried piecing it together using information I have found online but nothing specific to my request.

I've tried things like -

(set: $diceroll to (random: 1, 6) + $strength)
(if: $diceroll is >= 10

And this is where I get muddled, I don't know if it can add the "+$strength" or whether that needs to be a numeric value and I'm not sure what to add in at the end of the "if" statement to display an outcome and to set up and "else" statement to show another outcome.

What would be the best way to go about something like this?

thanks for any help you can offer

K00pa.

Comments

  • edited September 2015
    The code you've written so far is close to what you want.
    (set: $diceroll to (random: 1, 6) + $strength)
    
    For your example of $strength being 5 this will set $diceroll to between 6 and 11.
    (To mention a pet peeve of mine, the singular of dice is die, so really the variable should be called $dieroll. It doesn't really affect what you're doing, it's just something that bugs me.)

    When checking if the roll is greater or equal than 10 you don't need the word 'is'. That's just used when checking if a variable is equal to a value. So for your example you'd use:
    (if: $diceroll >= 10)[A hit.](else:)[A swing and a miss.]
    

    Though you'd probably want to reduce the bandit's health, and check if the bandit is dead, when the player hits. So it'd be something like:
    (if: $diceroll >= 10)[A hit. (set: $bandit_health to it - 1)(if: $bandit_health <= 0)[The bandit has been slain]](else:)[A swing and a miss.]
    

    Hope that helps.
    *edited to fix the last example
  • Aha. Yes this seems to be doing the trick, thank you very much for the help.

    Also you are quite right, it should be die roll ;)

    Thanks again.
Sign In or Register to comment.