Raised This Month: $ Target: $400
 0% 

[STOCK] Clear a timer


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
thetwistedpanda
Good Little Panda
Join Date: Sep 2008
Old 10-06-2012 , 19:26   Re: [STOCK] Clear a timer
Reply With Quote #1

This stock goes back a few years, just about every coder has one or uses one lol... (in b4 trash)
__________________

Last edited by thetwistedpanda; 10-06-2012 at 19:27.
thetwistedpanda is offline
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 10-06-2012 , 20:55   Re: [STOCK] Clear a timer
Reply With Quote #2

Quote:
Originally Posted by thetwistedpanda View Post
in b4 trash
meh
__________________
retired
shavit is offline
SkydiveX
Member
Join Date: Jul 2012
Location: England
Old 10-30-2012 , 10:37   Re: [STOCK] Clear a timer
Reply With Quote #3

Never used it + Never understood what It does. :/.
I guess its because i'm a bad coder .
__________________

_____________________________________________ _______________
Pastafarian and proud!
SkydiveX is offline
Malachi
Senior Member
Join Date: Jun 2010
Location: USA
Old 01-18-2013 , 13:28   Re: [STOCK] Clear a timer
Reply With Quote #4

I'm trying to test if a one-time timer has expired yet, but I'm not having any luck.

The test:
if (g_hTimer != INVALID_HANDLE)

isnt doing what I thought it should.


Here is what I've tried:
Code:
#include <sourcemod>
#pragma semicolon 1

// Globals
new Handle:g_hTimer = INVALID_HANDLE; 

...

public Action:Hook_RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
{
    if (g_hTimer != INVALID_HANDLE)
    {
        KillTimer(g_hTimer);
        g_hTimer = INVALID_HANDLE;
    }
    g_hTimer = CreateTimer(30.0, ShowStatus, 0, TIMER_FLAG_NO_MAPCHANGE | TIMER_HNDL_CLOSE);
    return Plugin_Continue;
}
(I reconstructed my code as best I could)

So KillTimer (I've substituted CloseHandle - the docs suggest they're similar) causes a runtime error. Using TIMER_HNDL_CLOSE doesn't change this. The docs warn that a runtime error will happen if you pass KillTimer an invalid handle. I'm thinking this is because the test for INVALID_HANDLE isn't working.

FWIW here is the actual SM errors log:
Quote:
L 01/16/2013 - 18:46:32: [SM] Plugin "alltalkstatus.0.5.smx" encountered error 23: Native detected error
L 01/16/2013 - 18:46:32: [SM] Invalid data handle 0 (error 4) passed during timer end with TIMER_DATA_HNDL_CLOSE
L 01/16/2013 - 18:46:32: [SM] Unable to call function "ShowStatus" due to above error(s).
L 01/16/2013 - 18:46:40: [SM] Native "KillTimer" reported: Invalid timer handle 2730236 (error 1)
L 01/16/2013 - 18:46:40: [SM] Displaying call stack trace for plugin "alltalkstatus.0.5.smx":
L 01/16/2013 - 18:46:40: [SM] [0] Line 118, alltalkstatus.0.5.sp::Hook_RoundStart()
L 01/16/2013 - 18:53:48: [SM] Native "KillTimer" reported: Invalid timer handle 2730236 (error 1)
L 01/16/2013 - 18:53:48: [SM] Displaying call stack trace for plugin "alltalkstatus.0.5.smx":
L 01/16/2013 - 18:53:48: [SM] [0] Line 118, alltalkstatus.0.5.sp::Hook_RoundStart()
I saw your code and couldn't help but wonder where I might be going wrong. Maybe I'm just missing something simple here.
Malachi is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:28.


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