I've been playing around with Twine a lot and I still learn new things and there are all sorts of things for me to do in Twine. So I figured it was time for me to get into the big-boy scripting.
For instance, random rolls. Like a D-20 or so. And if a certain number is rolled, or randomly generated, I could use that to my advantage by playing out different scenarios in my game. Like for example, I open a passage and a random number is rolled as the player-character finds loot, like coins or something. A random amount of coins.
Is there a script or a macro for random rolls? Like, I dunno, something simple like <<roll 20 $money>> for a random number between 1 and 20 to add to $money.
Comments
Okay... Now how do I use it to bring up different passages? How can I add it to a $money variable?
I believe you're using SugarCube, aren't you?
If so, you can use the
random(min, max)
utility function. For example: To use that for an amount of coins, let's say, you might do something like these:That's off by one.
Math.floor(Math.random()*6)
returns05
, you'd need to add1
to that if you wanted a range of16
.The reason being that
Math.random()
returns a real in the range:0.00.999~9
, so multiplying it by6
yields0.05.999~94
, which when floored yields05
.That's off by one.
Math.floor(Math.random()*6)
returns05
, you'd need to add1
to that if you wanted a range of16
.The reason being that
Math.random()
returns a real in the range:0.00.999~9
, so multiplying it by6
yields0.05.999~94
, which when floored yields05
.Ah!! Good to know!! Thanks.