Argonaft Posted October 7 Share Posted October 7 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 Share Posted October 8 When the player dies you should stop listening for timerdone event. Put this under death event listener. Spoiler inst:RemoveEventCallback("timerdone", onTimerDone) 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now