Enums and Strings - 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: Enums and Strings (
/showthread.php?tid=390641)
Enums and Strings -
adsy - 07.11.2012
I am having problems trying to compare a string (in variable format) with a stored variable.
Here is my code:
Код:
enum STUFF{
STRINGVARIABLE[MAX_PLAYER_NAME]
};
new VehicleCheck[MAX_VEHICLES][STUFF];
new pName[MAX_PLAYER_NAME];
//this is in a public call which includes vehicleid and playerid
VehicleCheck[vehicleid][STRINGVARIABLE] = GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
//this is in a different public call which includes vehicleid and playerid
if(VehicleCheck[vehicleid][STRINGVARIABLE] == GetPlayerName(playerid, pName, MAX_PLAYER_NAME)){
//do stuff
}
The error I get is about comparisson to an array.
I have tried this too:
Код:
GetPlayerName(playerid, pName, MAX_PLAYER_NAME)
if(VehicleCheck[vehicleid][STRINGVARIABLE] == pName){
Suggestions are welcome
Re: Enums and Strings -
cosbraa - 07.11.2012
string compare - strcmp
pawn Код:
GetPlayerName(playerid, pName, MAX_PLAYER_NAME)
if(!strcmp(VehicleCheck[vehicleid][STRINGVARIABLE], pName, true)){
Re: Enums and Strings -
PrawkC - 07.11.2012
Your're using GetPlayerName wrong, it stores the players name in the provided variable. It does not return the players name.
Re: Enums and Strings -
adsy - 07.11.2012
Quote:
Originally Posted by cosbraa
string compare - strcmp
pawn Код:
GetPlayerName(playerid, pName, MAX_PLAYER_NAME) if(!strcmp(VehicleCheck[vehicleid][STRINGVARIABLE], pName, true)){
|
DOH!
That makes sense, will try that when I get home and post the results
@PrawkC isnt this what you mean:
Код:
GetPlayerName(playerid, pName, MAX_PLAYER_NAME)
if(VehicleCheck[vehicleid][STRINGVARIABLE] == pName){
Re: Enums and Strings -
cosbraa - 07.11.2012
You can't compare 2 strings like that.
And PrawkC is talking about when you tried
pawn Код:
VehicleCheck[vehicleid][STRINGVARIABLE] = GetPlayerName(playerid, pName, MAX_PLAYER_NAME)
Use format(output[], len, const format[], {Float,_}:...) to store the players name into the STRINGVARIABLE.
EG:
pawn Код:
format(VehicleCheck[vehicleid][STRINGVARIABLE], MAX_PLAYER_NAME, "%s", GetPlayerName(playerid, pName, MAX_PLAYER_NAME));