View Full Version : SetTimerEx
NigNog1
12/03/2009, 02:42 PM
Passing strings in SetTimerEx doesn't work, and sometimes even causes server crashes.
public CreatePlayerMessage(iPlayerID, szMessage[], iSeconds, iOffset)
{
if(IsPlayerMessageShowing(iPlayerID) && iOffset == 0)
{
DestroyPlayerMessage(iPlayerID);
}
if(iOffset > 0)
{
SetTimerEx("CreatePlayerMessage", iOffset * 1000, false, "isii", iPlayerID, szMessage, iSeconds, 0);
}
else
{
// If the offset param is more than 0 and the timer has ran, the server will crash here:
iPlayerMessage[iPlayerID] = TextDrawCreate(191,372,szMessage);
// rest of code
TextDrawUseBox(iPlayerMessage[iPlayerID],1);
TextDrawBoxColor(iPlayerMessage[iPlayerID],0x00000000);
TextDrawTextSize(iPlayerMessage[iPlayerID],542,23);
TextDrawBackgroundColor(iPlayerMessage[iPlayerID],0x000000ff);
TextDrawFont(iPlayerMessage[iPlayerID],1);
TextDrawLetterSize(iPlayerMessage[iPlayerID],0.499999,2.000000);
TextDrawColor(iPlayerMessage[iPlayerID],0xffffffcc);
TextDrawSetProportional(iPlayerMessage[iPlayerID],1);
TextDrawSetShadow(iPlayerMessage[iPlayerID],1);
TextDrawShowForPlayer(iPlayerID,iPlayerMessage[iPlayerID]);
iTextTime[iPlayerID][0] = iSeconds;
iTextTime[iPlayerID][1] = GetTickCount();
}
}
P.S: the [pawn] tags cause unpredicatable results in terms of indention. It isn't my fault if the indention is slightly wrong.
Update:
It's actually the Textdraw that is causing the server crash because it's trying to display an empty string.
try to use 'd' instead of 'i' in settimerex formatting
Double-O-Seven
12/03/2009, 03:46 PM
SetTimerEx crashes the server, when you want to use a string ;)
NigNog1
12/03/2009, 03:54 PM
try to use 'd' instead of 'i' in settimerex formatting
Symbols d and i both represent integers so it will not make a difference. And if you would have read my post you would have realised that the bug happens when passing strings.
try to use 'd' instead of 'i' in settimerex formatting
Symbols d and i both represent integers so it will not make a difference. And if you would have read my post you would have realised that the bug happens when passing strings.
Ah, sorry ;X
so, try to define array size?
ex:
public CreatePlayerMessage(iPlayerID, szMessage[256], iSeconds, iOffset)
kaisersouse
12/03/2009, 03:58 PM
try to use 'd' instead of 'i' in settimerex formatting
Symbols d and i both represent integers so it will not make a difference. And if you would have read my post you would have realised that the bug happens when passing strings.
Ah, sorry ;X
so, try to define array size?
ex:
public CreatePlayerMessage(iPlayerID, szMessage[256], iSeconds, iOffset)
Doing that it will only pass the 255th char in the string
try to use 'd' instead of 'i' in settimerex formatting
Symbols d and i both represent integers so it will not make a difference. And if you would have read my post you would have realised that the bug happens when passing strings.
Ah, sorry ;X
so, try to define array size?
ex:
public CreatePlayerMessage(iPlayerID, szMessage[256], iSeconds, iOffset)
Doing that it will only pass the 255th char in the string
i know but it may help
Harry_Gaill
13/03/2009, 10:12 AM
No, he wants the entire string, not 1 character.
No, he wants the entire string, not 1 character.
ah, sorry, but doing this will pass 255 chars not 255th char
ICECOLDKILLAK8
13/03/2009, 11:36 AM
No, he wants the entire string, not 1 character.
ah, sorry, but doing this will pass 255 chars not 255th char
Nope, It will select the 256th char from the string; if any and thats all that it will use
lesley
13/03/2009, 12:16 PM
Hmm.. may it be you are passing '0' as duration parameter for the SetTimer when the function is executed 2nd time...?
No, he wants the entire string, not 1 character.
ah, sorry, but doing this will pass 255 chars not 255th char
Nope, It will select the 256th char from the string; if any and thats all that it will use
I very often use this and it works...
Norck
17/08/2010, 06:41 AM
If there is a few timers on the same function, and function has a "string" argument, in all cases it will receive a value that has been used in the last timer.
Here is an example code:
forward printstr(string[]);
public printstr(string[])
{
printf("%s",string);
return 1;
}
public OnGameModeInit()
{
SetTimerEx("printstr",1000,false,"s","first string");
SetTimerEx("printstr",2000,false,"s","second string");
SetTimerEx("printstr",3000,false,"s","third string");
return 1;
}
And here is how it looks in the server console:
third string
third string
third string
Hiddos
17/08/2010, 08:22 AM
Bug confirmed here.
cyber_punk
18/08/2010, 08:21 AM
Confirmed Tannz0rz just send me a scripting passing a string and it crashed the server, would be nice to have this bug fixed in 0.3b
dax123
23/08/2010, 06:47 AM
when using SetTimerEx() ( or CallLocalFunction() etc... ), if you try to send the null string through "s" argument
the server will crash.
for example:
SetTimerEx( "Coooool", 1000, 0, "s", "" ); // it will crash the server.
if you want to send the null string you should handle them
#define NULL {1,0}
SetTimerEx( "Coooool", 1000, 0 "s", (strlen(str))? (str):(NULL) );
And detect the null string with this fake function
#define isnull(%1) ((%1[0] == 0) || (%1[0] == 1 && %1[1] == 0))
hope this helps. thanks.
leong124
24/02/2011, 02:59 AM
Yes it is a bug that I've reported it before:(
But for passing null strings in SetTimerEx/CallLocal/RemoteFunction,
you'll need to pass \1(or \1\0) to represent a null string.
That's why the isnull macro will check for \1\0 but not only \0.
No good solutions at all I think.
You may create a global array of string to store the strings and pass the cell index(which is an integer that will not cause bug) in SetTimerEx.
vBulletin® v3.8.6, Copyright ©2000-2013, Jelsoft Enterprises Ltd.