Author Topic: HUD just disappeared by calling "on_started()"  (Read 3181 times)

0 Members and 1 Guest are viewing this topic.

HarleyDavidson
  • Guest
HUD just disappeared by calling "on_started()"
« on: January 20, 2017, 02:22:05 PM »
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?

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
Re: HUD just disappeared by calling "on_started()"
« Reply #1 on: January 20, 2017, 02:28:01 PM »
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
Code: (lua) [Select]
game:register_event("on_started", function()
   ...
end)
instead of
Code: (lua) [Select]
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.

HarleyDavidson
  • Guest
Re: HUD just disappeared by calling "on_started()"
« Reply #2 on: January 20, 2017, 02:35:12 PM »
Thanks for this super fast reply!
Now it works, here's my script now:

Code: [Select]
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