+2 votes
by (2.2k points)
edited by

I'm using twine2.

This is the code I'm using. I'm trying to have multiple dice rolls in the same passage as well as taking away the 'nah' choice in the case of choosing to roll. Is there a way I can accomplish it? And if so, can you walk me through the code because coding is not my strong suit.

You pick up your dice and roll. 

(click: "roll")
[{
(set: $diceroll1 to (random: 1,6))
(set: $diceroll2 to (random: 1,6))
(set: $result1 to $diceroll1 + $diceroll2)
(if: $result1 is 7 or it is 11)[Uh, it seems you got a point?]
(else-if: $result1 is 2 or it is 3 or it is 12)[Looks like you've lost given by their sly grins]
(else-if: ($result1 >= 4 and it <= 6) or (it >= 8 and it <= 10))[Point? No? I don't know. Could be a tie.]
}]

Do you want to roll again?

Yeah or nah? 

(Click: "Yeah")
[{
(set: $diceroll1 to (random: 1,6))
(set: $diceroll2 to (random: 1,6))
(set: $result1 to $diceroll1 + $diceroll2)
(if: $result1 is 7 or it is 11)[How the shiz does this even work?]
(else-if: $result1 is 2 or it is 3 or it is 12)[I think you've won!]
(else-if: ($result1 >= 4 and it <= 6) or (it >= 8 and it <= 10))[You lost.]
}] 
(click: "nah")[Well, that's a shame. Let's get out of here.]

 

1 Answer

0 votes
by (210 points)

Well, for the first part of your code, you can do this:

(click: "roll")
[{
(set: $result1 to (random: 1,6)+(random: 1,6))
(if: $result1 is 7 or it is 11)[Uh, it seems you got a point?]
(else-if: $result1 is 2 or it is 3 or it is 12)[Looks like you've lost given by their sly grins]
(else-if: ($result1 >= 4 and it <= 6) or (it >= 8 and it <= 10))[Point? No? I don't know. Could be a tie.](show:?cloaked)
}]

|cloaked)[Do you want to roll again?
Yeah or nah?]

You can set $result1's value to be a sum of two random rolls (unless you want to use $diceroll as a variable somewhere else, in which case your code is right).

The (show:?cloaked) macro will hide the "try again" session until the player rolled.

For the next part, I'm sorry, I could not figure out how hide the Nah button. You can link the "Yeah" word back to the dice passage, and put the whole try again session into an (if: ) that will prevent the player to try a third time. Like this:

(if: $tryagain is true)[(set: $tryagain to false)Try again? [[Yeah]] or [[Nah]]?](else:)[You already tried twice!]

I hope this helps a little bit.

by (159k points)

The correct way to test if the value of variable is equal to either Boolean true or false is:

(if: $var)[Var is true]
(if: not $var)[Var is false]

 

...