TombEngine
TombEngine copied to clipboard
validity of a movable object after loading
If one destroys a moveable object via the Moveable:Destroy()
method, the Moveable:GetValid()
method will return false.
If one saves the game and load it, the Moveable:GetValid()
method will return true.
For testing, I created a lua DestroyMoveable
function called from a volume
https://github.com/MontyTRC89/TombEngine/assets/116632612/ec617c4b-e527-43c6-a149-af6ed427ca0b
---- FILE: \bug.lua
local x, y = PercentToScreen(50, 80)
local phrases = DisplayString('Checkpoint!', x, y, Color(50, 250, 250), false)
phrases:SetFlags({ TEN.Strings.DisplayStringOption.BLINK, TEN.Strings.DisplayStringOption.CENTER })
if not IsStringDisplaying(phrases) then
ShowString(phrases)
end
local obj = TEN.Objects.GetMoveableByName("animating2_13")
LevelFuncs.OnLoad = function() end
LevelFuncs.OnSave = function() end
LevelFuncs.OnStart = function() end
LevelFuncs.OnControlPhase = function()
if IsStringDisplaying(phrases) then
phrases:SetKey("moveable state: " .. tostring(obj:GetValid()))
end
end
LevelFuncs.OnEnd = function() end
LevelFuncs.DestroyMoveable = function(arg)
TEN.Objects.GetMoveableByName(arg):Destroy()
end
I think the issue is in the lua code.
it's loading the obj during the script compilation time.
As I understand, the flow is going like this:
- The level starts, it does the initialization of every object.
- The lua scripts get compiled. (In the example code, here is when it will run this line: "obj = TEN.Objects.GetMoveableByName("animating2_13" because it's outside of the functions).
- Then, if it's the first cycle (the level is new) it does the OnStart function.
- Else, if it's a loaded game, it update the content with the data from the savegame, (the engine loading function), in this moment is when the object animating2_13 would get deactivated because was killed before.
- After that, it will execute the script function "OnLoad"
So, I'll check the issue reported here, but at first sight, I think it's an issue related to the used lua script, I think it should get the data of the moveable, during OnStart and OnLoad.