39
« on: September 05, 2015, 02:44:21 AM »
In game manager I keep getting an error towards the hud: "Error: In on_map_changed: [string "scripts/game_manager.lua"]:75: attempt to index upvalue 'hud' (a nil value)"
and the dialog box creates the error: Error: In on_started: "[string "scripts/dialog_box.lua"]:59: attempt to call field 'get_dialog_font' (a nil value)"
Clearly the problem is about the nil values but when I try defining either of them the error remains so I'm not quite understanding what to do....
Game_manager.lua -- Script that creates a game ready to be played.
-- Usage:
-- local game_manager = require("scripts/game_manager")
-- local game = game_manager:create("savegame_file_name")
-- game:start()
local game_manager = {}
-- Creates a game ready to be played.
function game_manager:create(file)
-- Create the game (but do not start it).
local exists = sol.game.exists(file)
local game = sol.game.load(file)
if not exists then
-- This is a new savegame file.
game:set_starting_location("house")
game:set_max_money(99)
game:set_max_life(12)
game:set_life(game:get_max_life())
game:get_item("rupee_bag"):set_variant(1)
end
sol.main.load_file("scripts/dialog_box.lua")(game)
sol.main.load_file("scripts/game_over.lua")(game)
local hud_manager = require("scripts/hud/hud")
local hud
local pause_manager = require("scripts/menus/pause")
local pause_menu
-- Function called when the player runs this game.
function game:on_started()
-- Prepare the dialog box menu and the HUD.
game:initialize_dialog_box()
hud = hud_manager:create(game)
pause_menu = pause_manager:create(game)
end
-- Function called when the game stops.
function game:on_finished()
-- Clean the dialog box and the HUD.
game:quit_dialog_box()
hud:quit()
hud = nil
pause_menu = nil
end
-- Function called when the game is paused.
function game:on_paused()
-- Tell the HUD we are paused.
hud:on_paused()
-- Start the pause menu.
sol.menu.start(game, pause_menu)
end
-- Function called when the game is paused.
function game:on_unpaused()
-- Tell the HUD we are no longer paused.
hud:on_unpaused()
-- Stop the pause menu.
sol.menu.stop(pause_menu)
end
-- Function called when the player goes to another map.
game.on_map_changed = function(game, map)
-- Notify the HUD (some HUD elements need to know that).
hud:on_map_changed(map)
end
local custom_command_effects = {}
-- Returns the current customized effect of the action or attack command.
-- nil means that the built-in effect.
function game:get_custom_command_effect(command)
return custom_command_effects[command]
end
-- Overrides the effect of the action or attack command.
-- Set the effect to nil to restore the built-in effect.
function game:set_custom_command_effect(command, effect)
custom_command_effects[command] = effect
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
local rupee_icon = sol.surface.create("hud/rupee_icon.png")
local rupee_text = sol.text_surface.create()
rupee_text:set_font("8_bit")
function game:on_draw(dst_surface)
rupee_icon:draw_region(0, 0, 12, 12, dst_surface, 10, 220)
rupee_text:set_text(game:get_money())
rupee_text:draw(dst_surface, 25, 225)
end
return game
end
return game_manager
And this is line 59 of the dialogbox script local font, font_size = sol.language.get_dialog_font()