I'm still confused for this valid property.
How, when, what trigger this property to be false and luobj is still not nil ?
As i discovered, when deleted a surface in one event, the surface will be actually destroyed in next tick. It seems this will happen. (I did not test it)
About LuaObj.valid property
Re: About LuaObj.valid property
Code: Select all
/c
global.entity = game.player.selected
game.print(global.entity.valid) -- true
game.player.selected.destroy()
game.print(global.entity.valid) -- false
Re: About LuaObj.valid property
thx your reply.DaveMcW wrote: Thu Aug 20, 2020 10:00 amIf you store anything in global, you must always check .valid because something else destroy it.Code: Select all
/c global.entity = game.player.selected game.print(global.entity.valid) -- true game.player.selected.destroy() game.print(global.entity.valid) -- false
should i consider like this .
In one tick lifecycle.
1. the system give u a valid entity
2. if you destory it using script, the entity is still not nil, but valid is false.
3. when this tick ended, in next tick, this entity will be nil
Another scenario.
1. in one event, destroy the entity and listen its destroy event
2. in destroy event , this entity is nil or invalid ?
3. previous event with the destroy event is in the same tick ?
Facto is using determisitic strategry. I think all results should be predicted.
Can i consider, Any system event will never give u invalid entity?
Only u manully destroyed it in one tick and access the entity in the same tick, that will happen, not nil but invalid.
Re: About LuaObj.valid property
Code: Select all
--- Clone carriage from the old.
-- @tparam class<Carriage> old_carriage
function Carriage:clone(old_carriage)
local restore = function(e)
-- @todo more accurate and flexiable is to check unit_number in CarriageDoorManager
if e.source.name ~= "player-port" then return end
local old_doors = old_carriage.doors
for k, door in pairs(old_doors) do
if door.factoobj == e.source then self:createDoorByClone(door, { factoobj = e.destination, carriage = self }) end
end
end
Event.on(defines.events.on_entity_cloned, restore)
self:cloneArea(old_carriage)
Event.remove(defines.events.on_entity_cloned, restore)
end
But i still wonder, all on_entity_cloned events will be triggered in this tick or some will be triggered in next tick ?