Enums and Strings
#1

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
Reply
#2

string compare - strcmp


pawn Код:
GetPlayerName(playerid, pName, MAX_PLAYER_NAME)
if(!strcmp(VehicleCheck[vehicleid][STRINGVARIABLE], pName, true)){
Reply
#3

Your're using GetPlayerName wrong, it stores the players name in the provided variable. It does not return the players name.
Reply
#4

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){
Reply
#5

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));
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)