I am using the newest implementation of middleclass and I am having issues with units being overwritten in what seems like a global scope, but they should be. I'll post the snippets of concern as well as a .love that will assert the output from an assertion I will also post.
First, I will show how I am loading units.
Code: Select all
--Load the GMTest Unit from file and pass it through Entity
local tU = Entity:new(require(dH.Units .. "GMTest"))
--Move the unit to the starting coordinates (found in data/maps/tutorial.lua
tU:moveTo(GameWorld.map.properties.sX, GameWorld.map.properties.sY)
tU:setGUID(1)
tU:setUnitLevel(69)
--Store the unit table into the GameWorld
GameWorld:storeUnit(tU)
tU = nil
--Reload a second unit to tU
tU = Entity:new(require(dH.Units .. "GMTest"))
--Move to an arbitrary location
tU:moveTo(2, 5)
--Change the GUID to something arbitrary
tU:setGUID(645969)
tU:setUnitLevel(3003)
--Store this unit
GameWorld:storeUnit(tU)
Code: Select all
function World:storeUnit(unit)
local id = unit:getGUID()
self.map.layers.unit[id] = unit
unit = {}
end
Code: Select all
self.map.layers.unit[1]:getGUID()
Here is the assert
Code: Select all
if self.map.layers.unit[1] then
assert(false, self.map.layers.unit[1]:getGUID())
end