[IMPORTANT]Compiler "error"!!!
#1

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:
pawn Код:
forward CountDownCuffing(playerid);//the timer
new countn3[MAX_PLAYERS];//indexed variable
new counttimer3[MAX_PLAYERS];//indexed variable
Good,now we set the timer:
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;
}
GOOD,now displaying it,AND HERE COMES the problem:
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;
}
GOOD so this is corrrect,but what if INSTEAD of:
pawn Код:
countn3[playerid]--;
we would have:
pawn Код:
countn3--;
The compiler would return an error,and that is:
Код:
error 033: array must be indexed (variable "countn3")
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:
pawn Код:
format(string,sizeof(string),"Stick to the player for %d seconds",countn3//HERE);
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?
Reply
#2

I think, if you don't index it. Compiler looks at it as a string, not as a single value.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)