Howdy, Stranger!

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

How to add init variables for a constantly updating game

Hello! I have an rpg game that's constantly being updated - new side quests or new plots, for example. I understand that if I update the StoryInit with new variables, players already with saved games won't be able to access these new additions. What would you recommend I do so that players won't constantly have to start new games just to get the new updates?

Thank you! I am currently on Twine 2.0.11 and Sugarcube 2.12

Comments

  • The best thing to do would be to use the Config.saves.onLoad handler to inject the new variables, however, that would require ongoing JavaScript maintenance on your end.

    The easiest thing to do would be to add a prehistory task to inject the new variables, which would only require ongoing TwineScript maintenance on your end.


    Here's an example of the latter. You'd need something like the following JavaScript to setup the task which will run a special passage, which I've named ExpansionInit: (Twine 2: goes in Story JavaScript; Twine 1: goes in script-tagged passage)
    prehistory['expansion-init'] = function () {
    	if (Story.has('ExpansionInit')) {
    		try {
    			Wikifier.wikifyEval(Story.get('ExpansionInit').text);
    		}
    		catch (ex) {
    			Alert.error('ExpansionInit', ex.message);
    		}
    	}
    };
    
    Once added, you will never have to touch that code again.


    Now, for the special passage, which you will have to maintain. Create a new passage named ExpansionInit and put something like the following within:
    <<if ndef $variableForExpansion1>>
    	<<set $variableForExpansion1 to …>>
    	<<set $anotherVariableForExpansion1 to …>>
    <</if>>
    <<if ndef $variableForExpansion2>>
    	<<set $variableForExpansion2 to …>>
    	<<set $anotherVariableForExpansion2 to …>>
    <</if>>
    
    Basically, you enclose the variables for each new expansion within an IF which is gated by the non-existence of one of the variables, so if and only if the key variable does not already exist will the set of variables for a particular expansion be initialized. See the <<if>> macro for details on the TwineScript ndef (not defined) operator.
  • edited December 2016
    Ohhh, thanks! Just to clarify: so from the code you supplied, if for example I want to add a "$town2map" variable, I would use the following code?
    <<if ndef $town2map>>
    	<<set $town2map to "yes">>
    <</if>>
    

    and adding this to the ExpansionInit passage means that going through new passages with $town2map will show up as "yes", even when using old saved games, right?
  • The variable(s) will be initialized for both new and existing games as long as the variable you check is undefined, yes.
  • I got it. Thank you!
Sign In or Register to comment.