AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   [Question] safely KillTimer() (https://forums.alliedmods.net/showthread.php?t=52737)

jopmako 03-18-2007 08:04

[Question] safely KillTimer()
 
Can we remove error log when KillTimer() using to a invalid handle?
Most time we don't need this log.

BAILOPAN 03-18-2007 12:33

Re: [Question] safely KillTimer()
 
Why would you call KillTimer on an invalid handle? If you're saving the timer Handle and you know the timer is gone, you should set it to 0 (or INVALID_HANDLE) to mark it as invalid.

jopmako 03-18-2007 13:58

Re: [Question] safely KillTimer()
 
Code:

new Handle:hTimer[65]
 
public OnClientPutInServer(client)
{
  hTimer[client] = CreateTimer(GetRandomFloat(5.0, 10.0), welcome_msg, client);
}
 
public OnClientDisconnect(client)
{
  if (IsValidHandle(hTimer[client]))
  {
      KillTimer(hTimer[client], true);
      hTimer[client] = INVALID_HANDLE;
  }
}
 
public Action:welcome_msg(Handle:timer, client)
{
  // coding...
 
  hTimer[client] = INVALID_HANDLE;
}

Is this right?
thank you.

BAILOPAN 03-18-2007 14:06

Re: [Question] safely KillTimer()
 
This would fix your problem:
Code:
new Handle:hTimer[65]   public OnClientPutInServer(client) {    hTimer[client] = CreateTimer(GetRandomFloat(5.0, 10.0), welcome_msg, client); }   public OnClientDisconnect(client) {    if (hTimer[client] != INVALID_HANDLE)    {       KillTimer(hTimer[client]);       hTimer[client] = INVALID_HANDLE;    } }   public Action:welcome_msg(Handle:timer, client) {    // coding...      hTimer[client] = INVALID_HANDLE; }

Note that KillTimer()'s second parameter must be false... autoClose is only if you pass a Handle to the timer; you passed a client index.

jopmako 03-18-2007 14:18

Re: [Question] safely KillTimer()
 
oh, I see.
thanks a lot.


All times are GMT -4. The time now is 10:33.

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