If I have a timer that I've declared in the "game" context, and my character moves to a different map while the timer is still active, I can't figure out how to reference that timer.
race_timer = sol.timer.start(game, 140000, end_race_lost)
race_timer:set_with_sound(true)
Timer declared as above. I know the timer is still active when the map changes because the sound still plays. I also have the time displayed on screen using race_timer:get_remaining_time(). When the hero changes maps, the timer display disappears.
if race_timer ~= nil then
function map:on_draw(dst_surface)
local timer_icon = sol.surface.create("hud/timer.png")
local timer_time = race_timer:get_remaining_time() / 1000
local timer_text = sol.text_surface.create{
font = "white_digits",
horizontal_alignment = "left",
vertical_alignment = "top",
}
timer_icon:draw(dst_surface, 20, 55)
timer_text:set_text(timer_time)
timer_text:draw(dst_surface, 40, 60)
end
end
The display is disappearing because the timer reference goes to nil, which I'm intentionally checking for. If I comment out the check, I get an error message of "attempt to index global 'race_timer' (a nil value), but the value shouldn't be nil since the timer is in a "game" context, right? Should I be referencing it a different way, or is this a bug in the engine?