SA-MP Forums Archive
[IMPORTANT]Compiler "error"!!! - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: [IMPORTANT]Compiler "error"!!! (/showthread.php?tid=374829)



[IMPORTANT]Compiler "error"!!! - Cjgogo - 04.09.2012

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?


Re: [IMPORTANT]Compiler "error"!!! - Roko_foko - 04.09.2012

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