Howdy, Stranger!

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

Randomizing Variables

I have several variables in my game meant to represent different classes a player can end up with. There's a chain of questions meant to set up a character's class, but I also want an option if the player chooses a really scattershot combination of answers that doesn't fit any particular class. Basically, I want the class variable to be randomly assigned.

I tried to use Random to do this, but it kicked back that Random only allowed for numbers. Is there a way I'm missing to set random variables with a click? Thanks!

Comments

  • If you have your classes setup like (set: $classOptions to (array: $mage, $cleric, $rogue) for example, you can use the Macro "Either" to pick a random variable rather than just an integer:


    (set $myClass to (either: ...$classOptions) will set the player's class randomly to any of the ones defined in the $classOptions array. This will inherently make your $myClass variable become whatever variable type it gets randomly assigned. So if your $mage is already setup as its own Array, it could hold randomly assigned class stats (magicka, health, strength etc..)



  • You need to state which story format you are using, as answers can be different for each one.
  • greyelf wrote: »
    You need to state which story format you are using, as answers can be different for each one.

    I'm using Harlowe right now.
  • edited August 2015
    I have several variables in my game...

    This is how i set my random variables in sugarcube. I guess story format is not necesary in twine 2

    <<set $variable1 to random($lowerValue,$higherValue)>>
    <<set $variable2 to random($lowerValue,$higherValue)>>
    ...

    More in http://twinery.org/wiki/function#random_value_value
  • Klain wrote: »
    I guess story format is not necesary in twine 2
    Story format is just as necessary in Twine 2 as Twine 1 because the story format dictates the syntax of the macro language and what macros/functions are available to the story Author.

    The Harlowe version of your example would be:
    (set: $variable1 to (random: $lowerValue, $higherValue))
    (set: $variable2 to (random: $lowerValue, $higherValue))
    
    .. in Harlowe (random:) is a macro where as in SugarCube random() it is a Javascript function.
Sign In or Register to comment.