About random events (Sugarcube)

Twine Version: 2.3.14
Story Format: SugarCube 2.34.1

Context: The protagonist (let’s call her Mary), and her bratty little sister (Ana), are on a carnival, in one of those stands where you shoot at a target to win a prize (in this case, a stuffed toy for Ana). Each try cost $10. Mary will only try four times (the player don’t know that). I want to do in a way that, when the player chose to play:

Random event: win or lose

If the player win:
Mary gets the toy.
Ana: yey! (Ana approval +10)
[[leave]]

If the player loses 1 time:
Ana: keep trying!
[[try again: -$10]]
[[leave (Anna approval -10)]]

If the player loses 2 times:
Ana: keep trying!
[[try again: -$10]]
[[leave (Anna approval -10)]]

If the player loses 3 times:
Ana: keep trying!
[[try again: -$10]]
[[leave (Anna approval -10)]]

if the player loses four times consecutively:
Mary gives up.
Ana: what a shame…. thanks for trying anyway (Ana approval +5)
[[leave]]

Something like that! Is it possible? If you think I could do this in a better/more practical way you can tell me!

Sorry for my English, it’s not my native language :sweat_smile:

I’m confused here, what you describe does not look like a random event, but a random resolution.
Of course a random event can have a random resolution!

Assuming you really describe a random resolution you can have something like this:
I’m proposing multiple passages to offer you a chance to describe environment and reactions better than a loop.

Passage FirstTry

Descriptive text of the scene
<<set $Money -=10>>
<<if random(1, 2)  ==1>>You manage to lift the bear to the air all the way.
Ana is very happy!<<set $Toycaught to "Success">>
[[Leave]]<<else>>You fail miserably and Ana is not very happy!
[[Would you like to try again... at a cost of $10?|SecondTry]]
[[Better to give up while you still have money|Leave]]<</if>>

Passage SecondTry

Descriptive text of the scene, adding some sense of impatience from young Ana.
<<set $Money -=10>>
<<if random(1, 2)  ==1>>You manage to lift the bear to the air all the way.
Ana is very happy!<<set $Toycaught to "Success">>
[[Leave]]<<else>>You fail miserably again and Ana can't believe how clumsy you are.
[[Would you like to try again... at a cost of $10?|ThirdTry]]
[[Better to give up while you still have money|Leave]]<</if>>

Passage ThirdTry

Descriptive test of the scene, Ana should probably grow really impatient,
maybe starting to comment on your obvious lack of skill.
<<set $Money -=10>>
<<if random(1, 2)  ==1>>You manage to lift the bear to the air all the way.
Ana is very happy, and somewhat relieved!<<set $Toycaught to "Success">>
[[Leave]]
<<else>>You fail miserably still and Ana  starts to look to think you won't make it.
[[Would you like to try again... at a cost of $10?|FourthTry]]
[[Better to give up while you still have money|Leave]]<</if>>

Passage FourthTry

Descriptive test of the scene, Ana might not expect any positive outcome
at this point, probably dejected because of her great sister failing again and again.
<<set $Money -=10>>
<<if random(1, 2)  ==1>>You manage to lift the bear to the air all the way.
Ana is very happy! She can't believe you made it and wildly jumps all around you.
<<set $Toycaught to "Success">>
[[Leave]]
<<else>>You fail miserably and Ana is not very happy!
She tells you blankly you'd better to stop now, it's obvious you won't succeed.
<<set $Toycaught to "Fail4">>
[[You follow her advice, utterly ashamed having not leave up to your baby sister expectations.|Leave]]<</if>>

Passage Leave

<<if ndef $Toycaught>>Ana is really noisy about your failure.
<<set $AnaAffection -=10>>
<<elseif $Toycaught == "Success" >>Ana looks up to you, she's proud her sister
could do the deed and she's happy you've given her the toy.
<<set $AnaAffection +=10>>
<<else>>Ana is sad, but she tries to comfort you.
"You tried, sis, it's bad luck you couldn't catch it, that's all".
<<set $AnaAffection +=5>><</if>>
<<unset $Toycaught>>
Text about what happens next

Everything in a single passage CarnivalThrow
(assuming the variables $annaApproval and $money)

:: CarnivalThrow
<<set _successfulThrow = either(true, false)>>\
<<set _numberOfThrows = visited()>>\
You try...
<<if _successfulThrow>>\
  You won!
  [[Leave (Anna approval +10)|NextPassage][$annaApproval += 10]]
<<elseif _numberOfThrows === 4>>\
  You missed four times.
  [[Leave (Anna approval +5)|NextPassage][$annaApproval += 5]]
<<else>>\
  You missed.
  Keep trying?
  [[Try again (-$10)|CarnivalThrow][$money -= 10]]
  [[Leave (Anna approval -10)|NextPassage][$annaApproval -= 10]]
<</if>>
1 Like

thank you so much!! this is exactly what i needed!

1 Like

thank you so much!! this is exactly what i needed!

1 Like