• Remove timer when frame closes
    10 replies, posted
Hi Is there a way to remove a running timer once the user closes the frame? [lua] local Window = vgui.Create("DFrame") -- some stuff here timer.Create("myTimer", 1, 0, function () print("I am still running") end) [/lua] Is there an OnClose hook or something I can use to do this? Thx
you can use a button with windows:SetVisible(false) and timer.Destroy("mytimer") in the doclick function and hide the exit button with windows:ShowCloseButton( true )
Thanks for the reply. That does work of course; but is there any other way?
Just use timer.Destroy
[QUOTE=LuckyLuke;22577248]Just use timer.Destroy[/QUOTE] [b]Is there an OnClose hook or something I can use to do this? [/b]
[lua]Window.OnClose = function() timer.Destroy( "myTimer" ) end [/lua]
[QUOTE=Willox;22577661][b]Is there an OnClose hook or something I can use to do this? [/b][/QUOTE] Yes: [lua] if not Window:HasFocus() then timer.Destroy( "myTimer" ) [/lua]
[QUOTE=H0rsey;22577826]Window.OnClose = function() timer.Destroy( "myTimer" ) end [/QUOTE] This is what I have been looking for; unfortunately, it does not work. There probably is no ".OnClose" for a DFrame. Thank you anyway, I ended up using a separate close button as suggested by slay3r36. EDIT: [QUOTE=vexx21322;22577963]Yes: if not Window:HasFocus() then timer.Destroy( "myTimer" ) [/QUOTE] Where would I put this exactly? This condition would have to be regularly checked.
[QUOTE=_nonSENSE;22578010]This is what I have been looking for; unfortunately, it does not work. There probably is no ".OnClose" for a DFrame. Thank you anyway, I ended up using a separate close button as suggested by slay3r36. EDIT: Where would I put this exactly? This condition would have to be regularly checked.[/QUOTE] I think in Window:Think() That function runs when Window is open, or you could just create a seperate timer to check every 10ms. Sorry if I can't help more, I'm also very new to lua.
[QUOTE=vexx21322;22578118]I think in Window:Init() That function runs when Window is open, or you could just create a seperate timer to check every 10ms. Sorry if I can't help more, I'm also very new to lua.[/QUOTE] Hehe, I would be creating a new timer to destroy another timer :biggrin: this unfortunately is not an option for me. Thanks for the suggestions though!
From what you quoted and from what I can read now, he changed the Function from init, to Think, which should work.
Sorry, you need to Log In to post a reply to this thread.