Without understanding more about what your "questline" variables are doing, when, where, why, how many, etc., I can't offer a great amount of specific advice.
If your "questlines" are simply a bunch of state variables crunched together, don't. SaveState does that for you. Just use discrete variables, use arrays, or, if you have a ton of Boolean values, use BitN.
If you have an existing tease showing use of these values, it would help me understand more what you're after. If there's not really an existing tease yet, think about using arrays for storing your values, and then abstracting getting/setting them with functions:
Code: Select all
// In init script
// Create a SaveState to track our variables
var gameState = new window.SaveState({
store: window, // Our state will be stored in the global (window) object
autoLoad: true, // We'll auto-load the variables below as state variables
// Alternativly, state variables can be defined here via:
// state: {varName: varValue, ..., ...}
})
// Define global game state variables that need to be saved, and only game state vars, here
// Don't prefix with "var", else they will be ignored by the SaveState variable auto loader
// Don't set/use/define any of the variables below before their initialization here
// *** WARNING: Removing/renaming/inserting/re-ordering these variables will invalidate any current saved game state!
// (you can _append_ new ones)
questlines = Array.apply(null, Array(4)).map(String.prototype.valueOf,"b") // Init array of 4 with default value of "b"
// ... surely there will be more state variables here ...
// ^^ You CAN append new variables just above here without invalidating previous save states!
// *** No more game state vars that need to be saved by gameState.save() and restored by gameState.load() after here ***
gameState.loadStates() // Record all the variables from above as part of our save state
// support functions
function setQL(i,v) {
questlines[i] = v
// We could do a gameState.save() here, if you always wanted to save it on every change
}
function getQL(i) {
return questlines[i]
}
// Elsewhere, use via:
setQL(0, 'k') // set questline 1 (0) to 'k', whatever that means.
setQL(1, 'z') // set questline 2 (1) to 'z', whatever that means.
if (getQL(0) === 'k') {
// do something
}
// Then you can save/restore questlines using gameState.save() and gameState.hasSave() && gameState.load()
If you have an existing tease and are already using variables like "questline1", "questline2", etc., then:
Code: Select all
// In init script
// Create a SaveState to track our variables
var gameState = new window.SaveState({
store: window, // Our state will be stored in the global (window) object
autoLoad: true, // We'll auto-load the variables below as state variables
// Alternativly, state variables can be defined here via:
// state: {varName: varValue, ..., ...}
})
// Define global game state variables that need to be saved, and only game state vars, here
// Don't prefix with "var", else they will be ignored by the SaveState variable auto loader
// Don't set/use/define any of the variables below before their initialization here
// *** WARNING: Removing/renaming/inserting/re-ordering these variables will invalidate any current saved game state!
// (you can _append_ new ones)
questline1 = "b"
questline2 = "k"
questline3 = "z"
questline4 = "g"
// ... surely there will be more state variables here ...
// ^^ You CAN append new variables just above here without invalidating previous save states!
// *** No more game state vars that need to be saved by gameState.save() and restored by gameState.load() after here ***
gameState.loadStates() // Record all the variables from above as part of our save state
// Then you can save/restore questline1-4 using gameState.save() and gameState.hasSave() && gameState.load()
If by "questline" you're alluding to multiple save slots, (doesn't look like this is what you're after, but just in case) you can have multiple save states storing/loading from the same global variables, if you wanted to save/restore different positions, like:
Code: Select all
// Define object for global variables we're saving/loading
var myStateVars = {
myTeaseVariable1: 'Default value for this variable',
anotherTeaseVariable: 2.3, // another default value
andAnotherTeaseVar: true, // and another default value for it
// and so on
}
// Helper function we'll use to shallow copy objects
function mergeObjects() {
var resObj = {}
for(var i=0; i < arguments.length; i += 1) {
var obj = arguments[i], keys = Object.keys(obj)
for(var j=0; j < keys.length; j += 1) {
resObj[keys[j]] = obj[keys[j]]
}
}
return resObj
}
// Instantiate save state #1
var myGameState1 = new SaveState({
stateKey: "1", // Store under the key "1"
store: window, // Save/load values to/from the global object
state: mergeObjects({}, myStateVars), // We'll store/load the same state vars, so dupe myStateVars
})
// Instantiate save state #2
var myGameState2 = new SaveState({
stateKey: "2", // Store under the key "1"
store: window, // Save/load values to/from the global object
state: mergeObjects({}, myStateVars), // We'll store/load the same state vars, so dupe myStateVars
})
// and so on for 3, 4, etc.
//Now you can save/restore all your state variables to different states separately.
myGameState1.save() // save values in myTeaseVariable1, etc., vars to tease storage under key "1"
// and
myGameState1.load() // restore values to myTeaseVariable1, etc., vars from tease storage's key "1"
// and/or
myGameState2.save() // save values in myTeaseVariable1, etc., vars to tease storage under key "2"
// and
myGameState2.load() // restore values to myTeaseVariable1, etc., vars from tease storage's key "2"
// you can also load for inspection into different objects, like:
var myTestState = myGameState1.load({})
if (myTestState.myTeaseVariable1 === 'something') {
// do something
}
Anyway, if you explain in more detail about what your end goal is, I may be able to offer better advice on how to get there.
How many variables you can store this way depends on the value size of the variables, how compressible the values are, and, if your values are larger strings with groups of 3 or more characters that are predictable, how you define your static dictionary. We get a total of 1024 bytes, including all key names and characters for encoding. If using my first example above, storing in an array, or second example, storing discretely, you'd probably be able to store around 400+ different single character "questlines".