Argonaft Posted October 7, 2023 Share Posted October 7, 2023 I decided to look in the console print(), but I saw that with each new timer there are more of them. It exactly runs the function several times. It is as if it remembers past runs and counts them as a separate completed timer, and the more iterations the worse it gets. I'm a complete newbie, so my head is broken on how to solve this. No matter what I do, the result is the same. It keeps repeating its past iterations to the end of the current timer. Maybe it's not a big problem, but I'm scared of how many function calls it can make after a small amount of play time. local dead_overload = 0 local function onTimerDone(inst, data) if data.name == "Timer_duplicate" then dead_overload = dead_overload + 1 print("Timer_Done", dead_overload) end end local function OnDeath(inst) print("Cycle Timer start: ") if inst.components.timer:TimerExists("Timer_duplicate") then inst.components.timer:SetTimeLeft(5) print("Start Current") else inst.components.timer:StartTimer("Timer_duplicate",5) print("Start_new") end end AddPlayerPostInit(function(player) if player.prefab == "test" then player:ListenForEvent("death", function(inst) OnDeath(inst) end) player:ListenForEvent("respawnfromghost", function(inst) inst:ListenForEvent("timerdone", onTimerDone) end) end end) Link to comment Share on other sites More sharing options...
_zwb Posted October 8, 2023 Share Posted October 8, 2023 When the player dies you should stop listening for timerdone event. Put this under death event listener. Spoiler inst:RemoveEventCallback("timerdone", onTimerDone) Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.
Please be aware that the content of this thread may be outdated and no longer applicable.