Author Topic: HUD Not showing??  (Read 351 times)

Boydie

  • Newbie
  • *
  • Posts: 13
    • View Profile
HUD Not showing??
« on: March 10, 2017, 03:02:24 pm »
Why isn't my HUD showing??
Here's my hud.lua

Code: [Select]
-- Script that creates a head-up display for a game.

-- Usage:
-- require("scripts/hud/hud")

require("scripts/multi_events")
local hud_config = require("scripts/hud/hud_config")

-- Creates and runs a HUD for the specified game.
local function initialize_hud_features(game)

  -- Set up the HUD.
  local hud = {
    enabled = true,
    elements = {},
  }

  for _, element_config in ipairs(hud_config) do
    local element_builder = require(element_config.menu_script)
    local element = element_builder:new(game, element_config)
    if element.set_dst_position ~= nil then
      -- Compatibility with old HUD element scripts
      -- whose new() method don't take a config parameter.
      element:set_dst_position(element_config.x, element_config.y)
    end
    hud.elements[#hud.elements + 1] = element
  end

  -- Destroys the HUD.
  function hud:quit()

    if hud:is_enabled() then
      -- Stop all HUD elements.
      hud:set_enabled(false)
    end
  end

  -- Returns whether the HUD is currently enabled.
  function hud:is_enabled()
    return hud.enabled
  end

  -- Enables or disables the HUD.
  function hud:set_enabled(enabled)

    if enabled ~= hud.enabled then
      hud.enabled = enabled

      for _, menu in ipairs(hud.elements) do
        if enabled then
          -- Start each HUD element.
          sol.menu.start(game, menu)
        else
          -- Stop each HUD element.
          sol.menu.stop(menu)
        end
      end
    end
  end

  -- Returns whether the HUD is currently shown.
  function game:is_hud_enabled()
    return hud:is_enabled()
  end

  -- Enables or disables the HUD.
  function game:set_hud_enabled(enable)
    return hud:set_enabled(enable)
  end

  -- Call this function to notify the HUD that the current map has changed.
  local function hud_on_map_changed(game, map)

    if hud:is_enabled() then
      for _, menu in ipairs(hud.elements) do
        if menu.on_map_changed ~= nil then
          menu:on_map_changed(map)
        end
      end
    end
  end

  -- Call this function to notify the HUD that the game was just paused.
  local function hud_on_paused(game)

    if hud:is_enabled() then
      for _, menu in ipairs(hud.elements) do
        if menu.on_paused ~= nil then
          menu:on_paused()
        end
      end
    end
  end

  -- Call this function to notify the HUD that the game was just unpaused.
  local function hud_on_unpaused(game)

    if hud:is_enabled() then
      for _, menu in ipairs(hud.elements) do
        if menu.on_unpaused ~= nil then
          menu:on_unpaused()
        end
      end
    end
  end

  game:register_event("on_map_changed", hud_on_map_changed)
  game:register_event("on_paused", hud_on_paused)
  game:register_event("on_unpaused", hud_on_unpaused)

  -- Start the HUD.
  hud:set_enabled(true)
end

-- Set up the HUD features on any game that starts.
local game_meta = sol.main.get_metatable("game")
game_meta:register_event("on_started", initialize_hud_features)
return true


Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1016
    • View Profile
Re: HUD Not showing??
« Reply #1 on: March 10, 2017, 04:06:16 pm »
Is there any error message?
Is initialize_hud_features() called?

Boydie

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: HUD Not showing??
« Reply #2 on: March 10, 2017, 04:23:16 pm »
Is there any error message?
Is initialize_hud_features() called?

How do I call it man? I'm new...

Thanks

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1016
    • View Profile
Re: HUD Not showing??
« Reply #3 on: March 10, 2017, 04:37:30 pm »
Don't call it yourself, but check that it is called (for example with a print statement).
It is the line
Code: Lua
  1. game_meta:register_event("on_started", initialize_hud_features)
that is supposed to call it when the game starts.

Boydie

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: HUD Not showing??
« Reply #4 on: March 10, 2017, 05:03:45 pm »
Don't call it yourself, but check that it is called (for example with a print statement).
It is the line
Code: Lua
  1. game_meta:register_event("on_started", initialize_hud_features)
that is supposed to call it when the game starts.

Where would I find that man? Sorry I'm a complete noob ahaha

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1016
    • View Profile
Re: HUD Not showing??
« Reply #5 on: March 10, 2017, 08:47:36 pm »
It is in the code you posted. Just do a print in initialize_hud_features() to know if the function is called or not, it will help understand the problem.

Boydie

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: HUD Not showing??
« Reply #6 on: March 11, 2017, 05:39:02 am »
It is in the code you posted. Just do a print in initialize_hud_features() to know if the function is called or not, it will help understand the problem.

I'm totally confused man, how do I fix it? ahha

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1016
    • View Profile
Re: HUD Not showing??
« Reply #7 on: March 11, 2017, 10:07:54 am »
I am just talking about basic debugging. Print stuff to know if a function is called. Then you know if the problem is that the function does not work or is never called.

Solarus is made for programmers, you don't have to know Lua but you need some programming experience. Otherwise I recommended other engines like Zelda Classic.

Boydie

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: HUD Not showing??
« Reply #8 on: March 11, 2017, 10:58:49 am »
I am just talking about basic debugging. Print stuff to know if a function is called. Then you know if the problem is that the function does not work or is never called.

Solarus is made for programmers, you don't have to know Lua but you need some programming experience. Otherwise I recommended other engines like Zelda Classic.

I know it's made for programmers man, but I want to learn, we all start out somewhere...

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1016
    • View Profile
Re: HUD Not showing??
« Reply #9 on: March 11, 2017, 11:22:58 am »
Ok. Then here is the good starting point to learn Lua: http://www.lua.org/pil/contents.html