How to add a random number generator in Squiffy?

0 votes
154 views
asked Mar 23 in Authoring by Natas (17 points)
recategorized Mar 27 by Alex
Hello there. I am Dandre and I am trying to create a text based game called Token Ino with Squiffy. The current problems I have been having has been using javascript to create a random number with the following psudeo code.

var randomnumber = function rng(min, max) {
  return Math.random() * (max - min) + min;
}

I am not sure if I am doing something wrong because if I try to call {randomnumber} or reference it in a if then statement it doesnt show a number or the vaule is equal with null. I simply want a variable that is randomly generatored. :) Also if it isnt too hard to implent is it possible for me to have chance in Squiffy implented in any kind of way using javascript? Imagine if you had a var 1 = 2 and with var 1 being to that increases your chances of succuding by 60 percent. This could also be used in the 'combat' system I am working on.

1 Answer

+1 vote
answered Mar 23 by Alex (486 points)
selected Mar 23 by Natas
 
Best answer

For this to work you need to set an attribute to the random number. To do this, call the "set" function to store the result of your randomnumber function.

For example:

    var randomnumber = function rng(min, max) {
      return Math.floor(Math.random() * (max - min) + min);
    }

    set ("mynumber", randomnumber(1,6));

Generated {mynumber}.

Live example: http://docs.textadventures.co.uk/squiffy/scratchpad/?gistid=74554bd2bb812a82df46&filename=gistfile1.txt

This site is now closed.
As of 1st November 2015, this site is a read-only archive. For more information see the intfiction forum post

Welcome to IF Answers, a site for questions and answers about Interactive Fiction.

Technical questions about interactive fiction development tools such as Inform, Twine, Quest, QuestKit, Squiffy, Adrift, TADS etc. are all on-topic here.

Non-technical questions about interactive fiction are also on-topic. These questions could be about general IF design, specific games, entering the IF Comp etc.
...