Simply checking for elements that don't exist works for any other table in lua but the ones representing Factorio "objects" FORCE an error even if I use pcall in an attempt to trap the error!
For example
Code: Select all
--assume tbl is a LuaPlayer object
if not tbl.childen then
--This is not a LuaGui or LuaGuiElement
if tbl.gui then
--This is a LuaPlayer; return the Player's LuaGui
return tbl.gui
else
--Not a LuaPlayer either. What is this thing?
return nil
end
else
--This is a LuaGui or LuaGuiElement; no correction needed
return tbl
end
A normal table doesn't throw this error and has unset keys "set" to nil as expected.
I expected reading unset keys on a factorio object to return nil just like any other Lua table while attempting to set a non-existent key on a factorio object to throw the "LuaPlayer does not contain the key children".
Is there any way to work around this problem with Factorio objects? It is really putting a damper on my plans.
