Declaring javascript functions

I've been playing around with Squiffy a little, and I think I'm getting the hang of how it handles javascript. However, there's a bit of a problem with modifying the javascript.

Sometimes, it might be useful to modify the core functions. Of course, you could do this by modifying the files after it's been compiled, but that isn't always convenient or easy. If you put, for example, squiffy.story.go = function(section) { into the JS for a section, then it will change when you visit that section. However, this means you end up having to put your functions into either the master section, or every section that uses them. And that is going to be rather inefficient.

I've tried putting them in the first section, which works until you're loading a saved game. And I wasn't sure how to get around that.

Here's a workaround, that might be slightly more efficient. Notably, it only defines the functions once:

    if (!squiffy.loaded_functions) {
      squiffy.loaded_functions = squiffy.story.sections['init'];
      if (squiffy.loaded_functions) {;

@inc turns

You've been playing this game for {turns} turns over {times_loaded} sessions!

    squiffy.story.go = function (name) {
      // whatever changes you want to make to the function

@inc times_loaded

(as usual, I'm writing code on the forum as a way of procrastinating from actually doing work. So I've not actually got Squiffy open to test this. But if anyone else thinks it's useful, take a look. I'm basically bodging together an init section, which is equivalent to Quest's UI Initialisation script.

This topic is now closed. Topics are closed after 60 days of inactivity.