Howdy, Stranger!

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

Keeping Random Content

Ok so we can create random content using the "Print either" function. But is there any way to keep that randomly generated thing for later? Such as, if I use Print either to randomly generate the details of a room, is there any way to save those details so that, if the player entered the room again, it wouldn't generate completely new details?

Comments

  • <<set $foo to either("bar", "baz", "qux")>>
    <<print $foo>>
  • Weirdly I had a similar question - so it's half answered... thanks!

    I went through your objects tutorial which which got me thinking of the other part of my question... I'm trying to work out how to use a list / array to randomise from? So instead of using:
    <<set $charactername to either("Andy", "Bob", "Chris", "Dave")>>
    <<print $charactername>>
    I want something like:
    <<set $namelist = {"Andy", "Bob", "Chris", "Dave"}>>
    <<set $charactername to RANDOM_ENTRY_FROM_$namelist>>
    <<print $charactername>>
    Basically the plan is to be able to set up all my lists in one place and then reference those instead of retyping the entire set.

    EDIT: I'm using Sugarcane format on v1.4.2 on Windows.
  • Actually managed to find another tutorial about arrays and figured it out from there - looks like I was mixing up my curly and square brackets when I tried doing it the first few times...
    <<set $namelist = ["Andy", "Bob", "Chris", "Dave"]>>
    <<set $charactername to $namelist[random(0,$namelist.length - 1)]>>
    <<print $charactername>>
  • Although not noted in the vanilla story format documentation for either() (Sugarcane is a vanilla format), if you pass a single array to it, then it will return a random element from that array.  So, you could write your code thus:

    <<set $namelist to ["Andy", "Bob", "Chris", "Dave"]>>
    <<set $charactername to either($namelist)>>
    <<print $charactername>>

    As an FYI to SugarCube users: SugarCube's implementation of either() acts the same with a single array, though differs in behavior when more than a single array is passed to it.
  • Thanks! Way easier than my way.
Sign In or Register to comment.