AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Stopping a non-repeatable timer (https://forums.alliedmods.net/showthread.php?t=301951)

condolent 10-11-2017 03:18

Stopping a non-repeatable timer
 
Hi,
How do I correctly stop a non-repeatable timer?

I made it a separate handle and named it gH_WeapRespawn and tried this on each event I want it to stop:
PHP Code:

public void OnRoundStart(Event event, const char[] namebool dontBroadcast) {
    if(
gH_WeapRespawn != null)
        
KillTimer(gH_WeapRespawn);


This is the timer:
PHP Code:

public Action WeaponRespawner(Handle timer) {
    
int client GetRandomValidClient();
    
    
RemoveEdict(g_iPistol);
    
RequestFrame(GiveGunFrameclient);
    
    
gH_WeapRespawn null;


The first code block gave me a Invalid Timer Handle error in server console.
Is that due to it being the wrong way or is it most likely something else in my code, perhaps?
I know this is the way to stop repeatable timers, but does it work the same for non-repeatable?

Peace-Maker 10-11-2017 03:52

Re: Stopping a non-repeatable timer
 
Just do delete gH_WeapRespawn; instead of KillTimer. Or set gH_WeapRespawn to null after KillTimer.

condolent 10-11-2017 03:55

Re: Stopping a non-repeatable timer
 
Quote:

Originally Posted by Peace-Maker (Post 2553774)
Just do delete gH_WeapRespawn; instead of KillTimer. Or set gH_WeapRespawn to null after KillTimer.

Which is better? Or do they do both do the same basically?

If it's the same I guess I'll use delete instead, just for the fact that I won't have to add more lines :3

sdz 10-11-2017 04:07

Re: Stopping a non-repeatable timer
 
Quote:

Originally Posted by condolent (Post 2553775)
Which is better? Or do they do both do the same basically?

If it's the same I guess I'll use delete instead, just for the fact that I won't have to add more lines :3

I believe I read somewhere that CloseHandle/Delete var frees it entirely from memory

hmmmmm 10-11-2017 08:48

Re: Stopping a non-repeatable timer
 
delete should set to null after freeing memory anyway, so I would go with that.

WildCard65 10-11-2017 15:29

Re: Stopping a non-repeatable timer
 
Quote:

Originally Posted by EasSidezz (Post 2553778)
I believe I read somewhere that CloseHandle/Delete var frees it entirely from memory

KillTimer and delete do the exact same thing for timer handles.


All times are GMT -4. The time now is 08:29.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.