I want to make it so that selecting a section title will randomly generate one of a few possible results. Does anyone know how to create this random function on Squiffy? I found this code:
var rnd = Math.ceil(Math.random() * 3); // random number between 1 and 3
squiffy.set("rnd",rnd);
{ if rnd=1: answer 1 }
{ if rnd=2: answer 2 }
But it doesn't seem to be working.
Any tips or suggestions are appreciated! Thanks!
See this thread: http://textadventures.co.uk/forum/squiffy/topic/q7ms8j7th0abymd64mnmbw/trying-to-assign-random-number-to-a-variable-attribute
Note: Javascript in Squiffy files needs to be indented (as per the Squiffy documentation).
Note 2: in the final example at that thread, you only need to put the function in your Squiffy file once. Then, whenever you want to generate a random number in a certain range and assign it to a Squiffy attribute, you just put this in your passage or section to call the function (using whichever numbers you want for the high and low number):
set("int", squiffy.getRndInteger(0,10));
In the example above, "int" is the name of the Squiffy attribute that will be assigned a random integer, '0' is the lowest integer in the range of random integers, and '10' is the highest. And 'getRndInteger' is the name of a Squiffy attribute that has been made equal to the randomizing function. It's basically a function itself.
I'm wondering the same thing, where choosing an action will have random results, but I want them to be based on other variables as well, making certain outcomes more or less likely to happen based on the values of said variables.