[SOLVED]Problem with my code (likely something really simple
Posted: Sat Jun 29, 2013 5:01 pm
EDIT: new problem. The same line:
Is giving me a new error: Attempt to call a table value.
Alright, I'm guess this is going to be something painfully basic that any self respecting Lua coder would know, but I've just started getting into Lua and my grasp of some of it is still a bit shaky...
In any case, I ran across an old project someone made a while back here called FEZ that is a framework for a component based entity system. I've been in the process of figuring out how it works looking at the demo code and FEZ's code, and I think I've got some idea of what's going on. The first piece of code I want to get working is basically just supposed to draw the map on the screen, just to make sure that the component system is working as intended so I can add the rest of the stuff in. Unfortunately, it doesn't run, and give me an error saying:
Now I know what this "means" in the sense that I know it's complaining that MapLoader doesn't actually exist. However, I'm not exactly sure what's wrong with what I'm doing... here's my preload.lua
Here's MapLoader.lua
I think everything that's relevant is in the .love I've attached. Some code was taken and slightly modified from the YakManExample that's on the FEZ github.
EDIT: gah, forgot to complete the title... then I had to wait for it to be accepted. Oh well, fixed now.
Code: Select all
mapLoader = MapLoader()
Alright, I'm guess this is going to be something painfully basic that any self respecting Lua coder would know, but I've just started getting into Lua and my grasp of some of it is still a bit shaky...
In any case, I ran across an old project someone made a while back here called FEZ that is a framework for a component based entity system. I've been in the process of figuring out how it works looking at the demo code and FEZ's code, and I think I've got some idea of what's going on. The first piece of code I want to get working is basically just supposed to draw the map on the screen, just to make sure that the component system is working as intended so I can add the rest of the stuff in. Unfortunately, it doesn't run, and give me an error saying:
Code: Select all
preload.lua:35: attempt to call global 'MapLoader' (a nil value)
Code: Select all
preload = {}
require "EntityFactory"
require "attributes.GameStateAttribute"
require "util.fez.ControllerManager"
require "util.fez.EntityManager"
require "util.fez.EntityTagManager"
require "util.fez.EventDispatcher"
require "util.fez.AspectManager"
require "util.fez.Component"
require "util.fez.ComponentCache"
require "controllers.MapController"
require "renderers.MapRenderer"
require "MapLoader"
function preload.init()
math.randomseed(os.time())
entityManager = EntityManager()
controllerManager = ControllerManager()
game = createGame()
gameState = entityManager:getComponentFromEntity( game, GameStateAttribute )
mapController = MapController( controllerManager )
mapRenderer = MapRenderer( controllerManager )
mapLoader = MapLoader() --This is the error line.
MapLoader:load( 'resources/levels/level1.lua' )
controllerManager:refresh()
end
return preload
Code: Select all
MapLoader = {}
function MapLoader:load( filepath )
local mapLuaFile = love.filesystem.load( filepath )
local leveldata = mapLuaFile()
local tileset = self:loadTiles( leveldata.tilesets[1] )
local mainLayer = mapdata.layers[1]
local tilemap = mainLayer.data
local map = entityManager:createEntity('level')
entityManager:addComponentToEntity( level, LevelAttribute( leveldata, tileset, tilemap ) )
entityManager:refreshEntity( level )
return map
end
function MapLoader:loadTiles( tileset )
local graphics = love.graphics
local quads = {}
local numberOfTiles = (tileset.imagewidth / tileset.tilewidth) * (tileset.imageheight / tileset.tileheight)
local image = graphics.newImage( tileset.image )
local spriteBatch = graphics.newSpriteBatch( image, 1000 )
local i = 1
for y = 0, (tileset.imageheight / tileset.tileheight)-1 do
for x = 0, (tileset.imagewidth / tileset.tilewidth)-1 do
quads[i] = graphics.newQuad(x * tileset.tilewidth, y * tileset.tileheight,
tileset.tilewidth, tileset.tileheight,
tileset.imagewidth, tileset.imageheight
)
i = i + 1
end
end
return {
['data'] = tileset;
['quads'] = quads;
['spriteBatch'] = spriteBatch;
}
end
return MapLoader
EDIT: gah, forgot to complete the title... then I had to wait for it to be accepted. Oh well, fixed now.