Im having some problems with my game, whenever the character dies the menu is loaded and it is meant to show a label with the player score, however the label doesnt show up. It shows up on the menu whenever I load the game however after the player dies and the menu loads, the label is no longer there. If anyone can help me i would greatly appreciate it.
Code from my score script:
local function load_highscore()
local filename = sys.get_save_file("sys_save_load", "highscore")
local data = sys.load(filename)
return data.highscore
end
local function save_highscore(highscore)
local filename = sys.get_save_file("sys_save_load", "highscore")
sys.save(filename, { highscore = highscore })
end
local function update_labels(highscore)
label.set_text("score#label", "SCORE\n" .. tostring(highscore))
end
function init(self)
self.highscore = load_highscore()
update_labels(self.highscore)
end
code from my menu:
local function animation5(self, node)
if gui.get_node("background") == node then
local to_color = gui.get_color(node)
to_color.w = 0.6
gui.animate(node, gui.PROP_COLOR, to_color, gui.EASING_OUT, 2.4, 0.1)
end
end
local function animation4(self, node)
local s = 1
gui.animate(node, gui.PROP_SCALE, vmath.vector4(s, s, s, 0), gui.EASING_INOUT, 0.24, 0, animation5)
end
local function animation3(self, node)
local s = 1.06
gui.animate(node, gui.PROP_SCALE, vmath.vector4(s, s, s, 0), gui.EASING_INOUT, 0.24, 0, animation4)
end
local function animation2(self, node)
local s = 0.98
gui.animate(node, gui.PROP_SCALE, vmath.vector4(s, s, s, 0), gui.EASING_INOUT, 0.24, 0, animation3)
end
local function animation1(node, d)
local start_scale = 0.7
gui.set_scale(node, vmath.vector4(start_scale, start_scale, start_scale, 0))
local from_color = gui.get_color(node)
local to_color = gui.get_color(node)
from_color.w = 0
gui.set_color(node, from_color)
gui.animate(node, gui.PROP_COLOR, to_color, gui.EASING_IN, 0.4, d)
local s = 1.1
gui.animate(node, gui.PROP_SCALE, vmath.vector4(s, s, s, 0), gui.EASING_IN, 0.4, d, animation2)
end
function init(self)
sound.play("go#sound", {delay = 0, gain = 5, pan = 0, speed = 1.15})
local d = 0.4
animation1(gui.get_node("new_game"), d)
animation1(gui.get_node("new_game_shadow"), d)
animation1(gui.get_node("new_game_button"), d)
d = 0.3
animation1(gui.get_node("quit"), d)
animation1(gui.get_node("quit_shadow"), d)
animation1(gui.get_node("quit_button"), d)
d = 0.1
animation1(gui.get_node("background"), d)
msg.post(".", "acquire_input_focus")
self.button = gui.get_node("new_game_button")
self.button2 = gui.get_node("quit_button")
self.is_over = false
self.is_over2 = false
node_to_hide = self.button
gui.set_enabled(node_to_hide, false)
node_to_hide2 = self.button2
gui.set_enabled(node_to_hide2, false)
end
function on_input(self, action_id, action)
if action_id == nil then
if gui.pick_node(self.button, action.x, action.y) then
if not self.is_over then
local node_to_hide = self.button
gui.set_enabled(node_to_hide, true)
self.is_over = true
end
else
if self.is_over then
local node_to_hide = gui.get_node("new_game_button")
gui.set_enabled(node_to_hide, false)
self.is_over = false
end
end
if gui.pick_node(self.button2, action.x, action.y) then
if not self.is_over2 then
local node_to_hide = gui.get_node("quit_button")
gui.set_enabled(node_to_hide, true)
self.is_over2 = true
end
else
if self.is_over2 then
local node_to_hide = gui.get_node("quit_button")
gui.set_enabled(node_to_hide, false)
self.is_over2 = false
end
end
end
if action_id == hash("fire") and gui.pick_node(self.button, action.x, action.y) then
msg.post("main:/loader#loader", "killmenu")
msg.post("main:/loader#loader", "load_level")
end
if action_id == hash("fire") and gui.pick_node(self.button2, action.x, action.y) then
msg.post("@system:", "exit", {code = 0})
end
end