It's strange. One of these cases where I almost has the answer. I know I have to make an array, so I can swith the active profile with switching the player integer:
profile[player]. But when I somehow try to put this into practice ... my brain just refuse to work with it.
What would be the best approach if I want to save level progress, topscore, etc, for two seperate profiles?
My current code goes like this:
_json:
/*===============================================================================
LOAD JSON
===============================================================================*/
#constant memoryFile = "boxmov1.json"
rem this type defines each level
type levelThing
numberOfDeaths as integer
topscore as integer
secondsPlayed as float
unlocked as integer
Endtype
rem This type defines all the data which is saved
Type dataThing
levels as levelThing[]
someStuff as integer
moreStuff as integer
Endtype
Global aGameData as dataThing[0] // only a single thingie in the array, at position zero
json_loadFile()
Return
// Load the file if it exists, otherwise it creates a new file
function json_loadFile()
if GetFileExists(memoryFile) = TRUE
aGameData.load(memoryFile)
else
tGameData As dataThing
tGameData.someStuff = 0
tGameData.moreStuff = 0
tGameData.levels.length = 3
aGameData[0] = tGameData
aGameData.save(memoryFile)
aGameData.load(memoryFile)
endif
endfunction
// Save the file
function json_saveFile()
aGameData.save(memoryFile)
endfunction