Found out how to do it:
The variable I want to save and reload is called deck_refills so make the follow code changes:
1. Give an argument to your onLoad function definition of saved_data:
Code:
function onLoad(saved_data)
2. Make an onSave function:
Code:
function onSave()
local data_to_save = {saved_count = deck_refills}
saved_data = JSON.encode(data_to_save)
return saved_data
end
3. In your main code add the following (note in my game deck_refills depends on the number of players if it isn't loaded from a saved game ):
Code:
-- load any saved data from a previous game save
local loaded_data = JSON.decode(saved_data)
-- check if the load, loaded anthing
if ( loaded_data == nil ) then
-- it didn't, so set deck_refills to -1 temporarily
deck_refills = -1
else
-- it did load data, so set deck_refills to the loaded data
deck_refills = loaded_data.saved_count
end
print('Deck Refills loaded as:' )
print(deck_refills)
-- if I set deck_refills to -1 I have to set it based on the number of players
if ( deck_refills == -1 ) then
if num_players == 3 then
deck_refills = 1
else
if num_players < 3 then
deck_refills = 0
else
deck_refills = 2
end
end
print('Deck Refills loaded as blank/-1 so set to:' )
print(deck_refills)
end