• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Is there a problem with this code?

Status
Not open for further replies.
Level 3
Joined
Aug 6, 2019
Messages
74
Look at this code,There are 100 leaks, right?
code.png
 
Level 39
Joined
Feb 27, 2007
Messages
5,013
First I noticed that it's the same timer being started i times; I thought it was multiple different timers. The way you've written it the timer will ultimately only be started for 100s once and only expire that one time.
If I destroyed it,Whether there is still a callback or event leak?
I'm not really sure I understand what you're saying. The object itself needs to be destroyed, either in the callback or some other function that runs after the callback.
 

Wrda

Spell Reviewer
Level 26
Joined
Nov 18, 2012
Messages
1,888
Pyrogasm is correct. This loop is useless by its current state, you destroy the timer in the callback (or in a function in callback), doing it outside would just prevent it from doing anything in the callback.
Lua:
TimerStart(t, i, false, function()
--do stuff
call DestroyTimer(t)
set t = nil --not sure if you actually need to null local variables in lua
end)
 
Status
Not open for further replies.
Top