Howdy, Stranger!

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

Stat Check Function

I want to figure out how to make a Stat Check function efficiently without having to make a new page every time to do so. Basically, I want a random number generator randomly select a number between 1 and 100. Then I want it to check that to a variable set in the Twine to be compared to that number, and if it's less than the generated number, then it moves you to one passage, If it's not then it goes to another. I want to do this using a JS script, but I don't know how to make "Passage" variables interact with "Script" variables. I also want it to basically be summoned using one passage line of code. Can someone help me?

Comments

  • Spark31 wrote:

    I want to figure out how to make a Stat Check function efficiently without having to make a new page every time to do so. Basically, I want a random number generator randomly select a number between 1 and 100. Then I want it to check that to a variable set in the Twine to be compared to that number, and if it's less than the generated number, then it moves you to one passage, If it's not then it goes to another. I want to do this using a JS script, but I don't know how to make "Passage" variables interact with "Script" variables. I also want it to basically be summoned using one passage line of code. Can someone help me?

    Well, you can do this in Twine code by just creating this passage (say, by naming it "summon"):

    <<if random(1,100) < parameter(0)>>
    <<goto parameter(1)>>
    <<else>>
    <<goto parameter(2)>>
    and then invoking it using the shorthand <<display>>:

    <<summon 25 "rare place" "common place">>
    But <<goto>> currently requires installing <<timedgoto>> to use.
  • Assuming you want them to click on a link to make the check, you can cheat and make use of the fact that macros run before exits...
    <<print "[[Try and lift the tree trunk (STR)|">><<if random(1,100) lte $stat.strength>><<print "LiftedTrunk">><<else>><<print "FailedTrunk">><<endif>><<print "]]">>
    This prints the exit link and specifies either passed or failed as the destination.

    You could probably put it in a macro...
    CheckStat:
    <<print "[[" + Parameter(0) + "|">><<if random(1,100) lte parameter(1)>><<print parameter(2)>><<else>><<print Parameter(3)>><<endif>><<print "]]">>
    Then you'd just:
    <<CheckStat "Try and lift the tree trunk (STR)" $stat.strength "LiftedTrunk" "FailedTrunk">>
    The cheat is that it's actually making the check before you click the link so the result of your click is preordained but unknown rather than unresolved.

Sign In or Register to comment.