So I think this is what I’ve gathered from all the information:
--- Name tag for lua module
--- “shared_data.module”
local M = {
player = {
highscore = 0,
score = 0
}
}
return M
and then Score save/load added to loader script
---loader script name
---loader
function save_gamedata(self)
-- reset player score
shared_data.player.score = 0
-- save gamedata
if not sys.save(save_file, shared_data) then
pprint(“gamedata not saved.”)
end
end
function load_gamedata(self)
-- load game data
local gamedata = sys.load(save_file)
if not next(gamedata) then
pprint(“gamedata empty”)
else
pprint(gamedata)
Shared_data.player.highscore = gamedata.player.highscore
end
end
function init(self)
msg.post(“.”, “acquire_input_focus”)
load_gamedata(self)
load_menu(self)
end
function on_message(self, message_id, message, sender)
…
elseif message_id == hash(“game_over”) then
unload_main(self)
load_menu(self)
save_gamedata(self)
msg.post(“/mainmenu#gui”, “update_score”, { score = gamedata.player.highscore }
elseif...
end
end
and finally add a script to the main menu gui script to post the score to the main menu score screen which is where the best score or high score will be shown
function on_message(self, message_id, message, sender)
if message_id == hash(“update_score”) then
-- set the score counter to new score
local score_node = gui.get_node(“score”)
gui.set_text(score_node, “SCORE: “.. message.score)
end
end
…fingers crossed this works (will have to try when i get home)