Why isn't my HUD showing??
Here's my hud.lua
-- 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
Is there any error message?
Is initialize_hud_features() called?
Quote from: Christopho on March 10, 2017, 04:06:16 PM
Is there any error message?
Is initialize_hud_features() called?
How do I call it man? I'm new...
Thanks
Don't call it yourself, but check that it is called (for example with a print statement).
It is the line
game_meta:register_event("on_started", initialize_hud_features)
that is supposed to call it when the game starts.
Quote from: Christopho 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
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
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.
Quote from: Christopho 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.
I'm totally confused man, how do I fix it? ahha
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.
Quote from: Christopho 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.
I know it's made for programmers man, but I want to learn, we all start out somewhere...
Ok. Then here is the good starting point to learn Lua: http://www.lua.org/pil/contents.html