Tuesday, 11 January 2011

"namespace not found" -- part 2

Ran this sucker under the debugger for a bit. The namespace not found error comes, not from GameMenu.lua as I'd supposed, but from startup,lua - the first script called.

startup has the job of setting up the script environment for everything that follows. So if startup goes wrong, it can have knock-on effects for everything else. Here's the code:

log("package.path = " .. package.path)

require "Game"

--
-- This script is defined in config.xml as the one that gets called
-- when the game first starts up.
--
-- It needs to do four things:
--
--      1 load the window definitions
--      2 load the game data (girls, locations, items, etc)
--      3 set up the background picture
--      4 push the first window onto the stack
--
--
-- There's no reason it can't run at load time
-- just make sure it returns false at the end so
-- the game engine doesn't look for a script() function to run
--

--
-- 2: game data -- todo
--
local game = Game:new()

--
-- preload window definitions
--
game:load_windows(
        "GameMenu.xml",
        "Intro.xml",
        "Chapter.xml",
        "Main.xml",
        "Cloning.xml"
)

--
-- set the background image for the game
--
game:set_background("background")

--
-- 4: initial window
--

show("game_menu")
--show("cloning")

return game


So here we see a game namespace being used. We're requiring "Game" which makes me wonder if this isn't  capitalisation issue. But it gets as far as loading the game windows - otherwise the game menu couldn't display.

Also interesting is that it loads twice, going by the gamelog. That initial log appears two times, which suggests the file is being parsed twice. It could be that there's an identical log statement in another file of course.

Overall though - I think I need to get my thoughts in order on how Lua embedding works, and how the game currently tries to do that. What I have at the moment is probably broken on all sorts of levels.

But I think that's a post for tomorrow. It feels like this has been a long day, somehow.

No comments: