local system = require('EntityComponent.system')
local system = require('EntityComponent.system')
local positioncomponent = require('EntityComponent.Components.positioncomponent')
local spritecomponent = require('EntityComponent.Components.spritecomponent')
local system = system.new()
local entityList = {}
local world = {}
world.__index = world
function world.new()
local self = {}
setmetatable(self, world)
return self
end
function world:update()
self:addPlayer(spritecomponent('Assets/lovie_modern.png'), positoncomponent(250,250))
end
function world:draw()
for key, value in ipairs(self.enityList) do
if value.spritecomponent ~= nil or value.positioncomponent ~= nil then
love.draw(value.spritecomponent, value.position.x, value.position.y)
end
end
end
function world:addPlayer(playerComponents)
for key, value in ipairs() do
table.insert(entityList, value)
end
end
return world
self:addPlayer(spritecomponent('Assets/lovie_modern.png'), positoncomponent(250,250))
function world:addPlayer(playerComponents) -- is this a table ? or have i do something else to do it a table ?
for key, value in ipairs(playerComponents) do
table.insert(entityList, value)
end
end
What does spritecomponent('Assets/lovie_modern.png') return? According to your original error, what you are passing to ipairs() is a nil value (ie. in your case playerComponents does not have a defined value). As such, spritecomponent() seems to be returning nothing for addPlayer() to use.
local spritecomponent = {}
spritecomponent .__index = spritecomponent
spritecomponent .__call = function(self, path) return spritecomponent.new(path) end
function spritecomponent.new(path)
local object = {}
object.image = love.graphics.newImage(path)
return setmetatable(object, spritecomponent )
end
return spritecomponent
- 'self' is a lua keyword, i don't think it's good practice to write 'local self'
- The 'setmetatable(self, spritecomponent )' function return the table with the metamethods, so you can combine those 2 lines.