Howdy, Stranger!

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

Can I set default values for variables? [SOLVED]

edited February 2014 in Help! with 1.x
I'm guessing the answer is 'no,' but I figured I'd ask:

Is there an easy way to set a default value for a variable (like, say, the player's $name), such that wherever I "test play" from, it'll be initialized to that default -- but if it's set in the course of the game, it'll be overridden with the new value?

Comments

  • It'd certainly be a helpful feature to have!  I've not encountered a way to do it so far, though I wonder if you could have a script that sets the values to your specified defaults whenever you run the game? 
  • Would it not just work to do <<set $name to "Defaulty McAnonymous">> in the Start passage (or a data passage <<display>>ed from Start), then change it later as needed?

    SugarCube also has the StoryInit special passage, which runs before Start and could contain initialization code like this. But I'm not sure whether that exists in the "vanilla" headers.
  • You can do that, but I don't think it works if you try the 'test from here' functionality (which would mean skipping the start passage). 
  • The Test Play From Here feature bypasses the Start passage entirely, so setting the variables there wouldn't work.

    SugarCube's StoryInit special passage does work with Test Play From Here feature (and initialization is exactly what it's for), but it's a SugarCube specific special passage.

    You could do somewhat clumsily it in the vanilla headers via the prerender task object.  Something like this should work:

    prerender.initialize = function ()
    {
    if (!state.history[0].variables["name"])
    {
    state.history[0].variables["name"] = "Soandso";
    }
    };
    That gets checked every time you render a passage though, hence the need for the conditional.
  • Works like a charm, thank you!
  • TheMadExile wrote:

    SugarCube's StoryInit special passage does work with Test Play From Here feature (and initialization is exactly what it's for), but it's a SugarCube specific special passage.

    I think this would be a useful feature for all story formats. Would anyone object if I add it to engine.js?
  • I think it'd definately be useful. 
  • That would be super. ^_^
  • What I actually want is for it to be called "StorySetup", since I feel that's a far nicer word than "Init(ialisation)", but w/e, I guess it's no biggie.

    Maybe I'll make "StorySetup" and "StoryInit" do the same thing.

    (No I won't.)

    (Maybe I won't.)

    EDIT: I just realised that "StorySetup" has this delicious verbal commonality with the <<set>> macro,  which is the macro that will be used most within it. Right, that's it, changing it now, English itself decrees it.
Sign In or Register to comment.