Delete an object
Posted: Sat Nov 04, 2017 10:54 am
Hello everyone.
Quite noob question but here is something I couldn't get.
I have an object which look like this :
Then I create a player object and add it to a list like this :
And then try to delete it :
Why player = nil do nothing ?
And Is there a way for an object/table to set itself as nil ?
Quite noob question but here is something I couldn't get.
I have an object which look like this :
Code: Select all
local Object = {}
--[[
Object definition
@return table : new Object
]]
function Object.new()
local self = require('script.object.gameobject').new()
--[[
Privates vars
--------------------------------]]
local update = 0
--[[
Publics vars
--------------------------------]]
self.publicVar = 'value'
--[[
Update
]]
function self.update()
--print('update')
end
--[[
Draw
]]
function self.draw()
--print('draw')
end
--[[
Delete
]]
function self.delete()
self = nil
end
return self
end
return Object
Code: Select all
player = Player.new()
gameObjectList[#gameObjectList + 1] = player
Code: Select all
player.delete()
player = nil
print(Inspect(gameObjectList)) -- Nothing happen
And Is there a way for an object/table to set itself as nil ?