I just copied all required scripts into my projects and the hud is displayed correctly.
But my hero is changed to the default tunic1 hero sprite, so I just wanted to change the sprite id.
Only the call of the function game:on_started() let the HUD disappear and I cannot figure out why.
Here's my game_manager.lua:
Quote
local game_manager = {}
local initial_game = require("scripts/initial_game")
-- Starts the game from the given savegame file,
-- initializing it if necessary.
function game_manager:start_game(file_name)
local exists = sol.game.exists(file_name)
local game = sol.game.load(file_name)
if not exists then
-- Initialize a new savegame.
initial_game:initialize_new_savegame(game)
end
function game:on_started()
end
game:start()
end
return game_manager
Only the call of the function "game:on_started()" is enough to let the hud disappear,
I do not change or call anything in this function...
There's no error message in the console. :(
Can anyone help me?
By defining the function game:on_started() here, you overwrite the one used by the HUD.
The correct way should be to define it as
game:register_event("on_started", function()
...
end)
instead of
function game:on_started()
...
end
Using register_event() is equivalent but allows to have several functions associated to the same event (on_started() here).
If a tutorial told you to write function game:on_started(), please tell me and I will fix it.
Thanks for this super fast reply!
Now it works, here's my script now:
local game_manager = {}
local initial_game = require("scripts/initial_game")
require("scripts/multi_events")
-- Starts the game from the given savegame file,
-- initializing it if necessary.
function game_manager:start_game(file_name)
local exists = sol.game.exists(file_name)
local game = sol.game.load(file_name)
if not exists then
-- Initialize a new savegame.
initial_game:initialize_new_savegame(game)
end
game:register_event("on_started", function()
local hero = game:get_hero()
hero:set_tunic_sprite_id("main_heroes/dominik")
end)
game:start()
end
return game_manager