String must be assigned to array - 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: String must be assigned to array (
/showthread.php?tid=425601)
String must be assigned to array -
klotebandit - 26.03.2013
Hi, im working on a ranking script and i want people to get a message when they rank up. However I don't know how to propperly use strings.
Код:
new newrank[MAX_PLAYERS];
new oldrank[MAX_PLAYERS];
if (score[playerid] >= 300){
newrank[playerid] = "***Marshall***";
}
if(oldrank[playerid] != newrank[playerid]){
format(stringb,sizeof(stringb),"~w~Rankup: ~g~%s",newrank[playerid]);
GameTextForPlayer(playerid,stringb,2000,5);
}
oldrank[playerid] = newrank[playerid];
I left a lot of code out since it is not important for this question. but i get an error wich says that the array is not indexed. as you can see i indexed it to the playerid. please help
Re: String must be assigned to array -
Neil. - 26.03.2013
pawn Код:
new newrank[MAX_PLAYERS][15];//15 as the len to store the string "newrank".
new oldrank[MAX_PLAYERS][15];//15 as the len to store the string "oldrank".
if (score[playerid] >= 300){
newrank[playerid] = "***Marshall***";
}
if(oldrank[playerid] != newrank[playerid]){
format(stringb,sizeof(stringb),"~w~Rankup: ~g~%s",newrank[playerid]);
GameTextForPlayer(playerid,stringb,2000,5);
}
oldrank[playerid] = newrank[playerid];
Re: String must be assigned to array -
klotebandit - 26.03.2013
Quote:
Originally Posted by Ken97
pawn Код:
new newrank[MAX_PLAYERS][15];//15 as the len to store the string "newrank". new oldrank[MAX_PLAYERS][15];//15 as the len to store the string "oldrank".
if (score[playerid] >= 300){ newrank[playerid] = "***Marshall***"; }
if(oldrank[playerid] != newrank[playerid]){ format(stringb,sizeof(stringb),"~w~Rankup: ~g~%s",newrank[playerid]); GameTextForPlayer(playerid,stringb,2000,5); } oldrank[playerid] = newrank[playerid];
|
Ok, that cleared some errors. however i still get an error wich says that these need to be indexed:
Код:
if(oldrank[playerid]//this != newrank[playerid]//this){
format(stringb,sizeof(stringb),"~w~Rankup: ~g~%s",newrank[playerid]);
GameTextForPlayer(playerid,stringb,2000,5);
}
Re: String must be assigned to array -
Neil. - 26.03.2013
Quote:
Originally Posted by klotebandit
Ok, that cleared some errors. however i still get an error wich says that these need to be indexed:
Код:
if(oldrank[playerid]//this != newrank[playerid]//this){
format(stringb,sizeof(stringb),"~w~Rankup: ~g~%s",newrank[playerid]);
GameTextForPlayer(playerid,stringb,2000,5);
}
|
You can try
Strcmp, since you're comparing two strings.
Re: String must be assigned to array -
Djole1337 - 26.03.2013
Yes you have to use strcmp, you can't compare strings like that == etc...
Re: String must be assigned to array -
klotebandit - 26.03.2013
Quote:
Originally Posted by Ken97
You can try Strcmp, since you're comparing two strings.
|
That did the trick, thank you