Howdy, Stranger!

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

Sugarcube- is there an easier/simpler way to dol this? (randomized risk/reward)

So I'm making a dungeon-crawler labyrinth style twine in which you can choose to enter a room and can either gain or lose currency (ORE). The following is a test example of a room with a risk rating of 4:

passage:tc1

<<if visited ("tc1") lte 1>>
<<set $dice to either (0,0,0,0,0,0,1,1,1,1)>>

<<if $dice is 0>>  you gain <<print $ore += 20>> ORE
<<endif>>

<<if $dice is 1>> you lose <<print $ore -=5>> ORE
<<endif>>
<<endif>>

<<if visited ("tc1") gte 2>>
already visited!
<<endif>>


so there's a 6/10 chance of gaining ore, and a 4/10 chance of losing ore
thing is, this is pretty clunky to put into every cave. I'm quite new to twine (this is only my second game), so I'm not sure how i would go about simplifying this. Is my best option just to edit it passage to passage in order to customize it to my needs? Thank you in advance!

Comments

  • Should this happen on every passage or only some?  Also, you were printing the total ore, not the gain/loss as it seems you intended.

    Anyway, the basics of what you want would be more like the following (upon the first visit only, there's a 60% chance to gain ore elsewise ore is lost).  Don't give visited() a parameter and it will check the current passage by default.  Use random() to determine the gain/loss status.  For example: (I dropped the "already visited" message, as I assumed it was for debugging purposes)

    <<nobr>>
    <<if visited() is 1>>
    <<if random(1, 10) lte 6>>
    <<set $ore += 20>>You gain 20 ORE
    <<else>>
    <<set $ore -= 5>>You lose 5 ORE
    <</if>>
    <</if>>
    <</nobr>>
    Depending on how often you want this to happen and where, wrapping it up into a widget would save you having to type it all in again (or making a task out of it to make it even more automated, though that would involve JavaScript).
  • Oh you're right! I did intend to print the amount of ore lost/gained instead of total, I was thinking myself in circles haha thank you so much.
    That really helps out! oh and it's only gonna display on certain passages. thank you again!
  • Since it's only going to be used in certain passages, I'd probably suggest making it into a widget.  For example (goes in a widget tagged passage):

    /% <<ore GAIN_PERCENT GAIN_AMOUNT LOSS_AMOUNT>> %/
    <<widget "ore">>\
    <<nobr>>
    <<if visited() is 1>>
    <<if random(1, 100) lte $args[0]>>
    <<set $ore += $args[1]>>You gain <<print $args[1]>> ORE
    <<else>>
    <<set $ore -= $args[2]>>You lose <<print $args[2]>> ORE
    <</if>>
    <</if>>
    <</nobr>>\
    <</widget>>
    Then simply do the following it in the appropriate passages:

    <<ore 60 20 5>> /% 60% chance to gain 20, else lose 5 %/
    If you don't need to alter the percentage chance of gaining ore or the amounts, then the widget could be simplified.
  • Thanks! Yes, I'll definitely do that!
Sign In or Register to comment.