04.09.2012, 09:15
OK,here's the problem, wich in my point of view, IS very important.It's about arrays/variables indexed to a player.In order to display it, you would use a textdraw, or a gametext,OR a string(for SendClientMessage),right?Well,let's show an example with a timer and a gametext:
Good,now we set the timer:
GOOD,now displaying it,AND HERE COMES the problem:
GOOD so this is corrrect,but what if INSTEAD of:
we would have:
The compiler would return an error,and that is:
OK,so far so good,AND here comes the real problem,if anyone can explain it.So we leave that line alone,unmodified,BUT,what if we have to index the variable INSIDE the string,when we're formatting the string:
Well,teh compiler returns NO ERROR,and when you go in-game the variable displays as 0 everytime.How about that?Why doesn't the compiler return ANY errors when we forget to index a variable inside a string formating?
pawn Код:
forward CountDownCuffing(playerid);//the timer
new countn3[MAX_PLAYERS];//indexed variable
new counttimer3[MAX_PLAYERS];//indexed variable
pawn Код:
COMMAND:cuff(playerid,params[])
{
//blabla code
countn3[playerid]=5;//we assigne a value to our variable
counttimer3[playerid]=SetTimerEx("CountDownCuffing",1000,1,"i",playerid);//we set the timer
return 1;
}
pawn Код:
public CountDownCuffing(playerid)
{
countn3[playerid]--;
new string[256];
format(string,sizeof(string),"Stick to the player for %d seconds",countn3[playerid]);
GameTextForPlayer(playerid,string,4000,4);
//blabla code
return 1;
}
pawn Код:
countn3[playerid]--;
pawn Код:
countn3--;
Код:
error 033: array must be indexed (variable "countn3")
pawn Код:
format(string,sizeof(string),"Stick to the player for %d seconds",countn3//HERE);