Howdy, Stranger!

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

How do you use config.saves.isAllowed?

edited August 2015 in Help! with 1.x
I'm not sure how to use this SugarCube configuration for specific passages?

Basically I'm looking for an option that will allow a player to set a higher difficulty by disabling all manual saves, including disk saves. So to do this I could disable manual saving on my save game passages.

If I can't work out a way to do that, I can imagine doing a system where I use an <<if>> macro to completely remove the save/load game links and just replace it with a simple "load autosave" button using Save.autosave.load(). Which, come to think of it, is a much simpler way to handle things.

Comments

  • edited August 2015
    The config.saves.isAllowed callback should return a boolean, true if saving is allowed or false if saving is disallowed. For example:
    config.saves.isAllowed = function () {
    	if ( /* Your negative condition here. */ ) {
    		return false;
    	}
    	return true;
    };
    

    Also, I thought you were using SugarCube 1.x? Save.autosave.load() is part of the 2.x Save API.
  • Well okay, I sitll don't understand the point of that, but I managed to do what I wanted anyway with the autosave load. Changed it to the 1.x verson of SaveSystem.loadAuto(). :)
  • You're using a custom UI, so the way you've gone is probably better for your use case.


    Beyond that. What didn't you understand? Seriously, I'm not trying to be difficult here.

    For those wishing to use it, you assign config.saves.isAllowed a function, which is then called by the save system whenever any type of save is requested. Its return value (true or false) determines whether the save is allowed to happen. If the callback returns true, then the save is allowed to proceed. If the callback returns false, then the save is not allowed to proceed and, depending on the situation, the player may receive a message to that effect.
  • edited August 2015
    Oh ok, well that helps explain it. I was thinking about it in terms of the explanation in the sugarCube docs of:
    Note: When setting the value to boolean true, you will likely also need to use the config.saves.isAllowed property to disallow saving on the start passage. Or, if you use the start passage as real part of your story and allow the player to reenter it, rather than just as the initial landing/cover page, then you might wish to only disallow saving on the start passage the very first time it's displayed (at story startup).

    I was thinking of something that was placed in individual passages, but it rather sounds like you need to use Javascript in the script passage to reference what passages are allowed to be saved on.
  • Claretta wrote: »
    Oh ok, well that helps explain it. I was thinking about it in terms of the explanation in the sugarCube docs of:
    Note: When setting the value to boolean true, you will likely also need to use the config.saves.isAllowed property to disallow saving on the start passage. Or, if you use the start passage as real part of your story and allow the player to reenter it, rather than just as the initial landing/cover page, then you might wish to only disallow saving on the start passage the very first time it's displayed (at story startup).
    That quote is not from the config.saves.isAllowed docs (which are simply, "Returns whether saving is allowed within the current context."). That's from the config.saves.autosave docs, and only points out instances where when having it enabled the use of config.saves.isAllowed may also be necessary.

    Claretta wrote: »
    I was thinking of something that was placed in individual passages, but it rather sounds like you need to use Javascript in the script passage to reference what passages are allowed to be saved on.
    All config object properties are scripting, so yes, that means they're best used within a script area (Story JavaScript [Twine 2] or a script-tagged passage [Twine 1]). And yes, one of the many things you could check for in config.saves.isAllowed is the current passage title.

    Some examples:
    /* No saving on the passage "Start". */
    config.saves.isAllowed = function () {
    	if (passage() === "Start") {
    		return false;
    	}
    	return true;
    };
    
    /* No saving on passages tagged with "nosave". */
    config.saves.isAllowed = function () {
    	if (tags().contains("nosave")) {
    		return false;
    	}
    	return true;
    };
    
    /* No saving on Friday. */
    config.saves.isAllowed = function () {
    	if ((new Date()).getDay() === 5) {
    		return false;
    	}
    	return true;
    };
    
    /* No saving on the passage "Start", passages tagged with "nosave", or Friday. */
    config.saves.isAllowed = function () {
    	if (passage() === "Start" || tags().contains("nosave") || (new Date()).getDay() === 5) {
    		return false;
    	}
    	return true;
    };
    
Sign In or Register to comment.