Returning string of enum -
hiok - 03.08.2013
I have a problem, this does not return the correct string, just some weird stuff:
pawn Код:
enum a {
str[MAX_PLAYER_NAME];
}
new array[MAX_PLAYERS][a];
public OnPlayerConnect(playerid) {
GetPlayerName(playerid, array[playerid][str], MAX_PLAYER_NAME);
}
returnPlayerName(playerid) {
// Printing array[playerid][str] here gives the correct result!
return array[playerid][str]; // This does not return the correct thing.
}
Re: Returning string of enum -
Konstantinos - 03.08.2013
May I ask why do you need this? You already store the name to str, why you need to use a function to return the name? Way too slower.
Re: Returning string of enum -
hiok - 03.08.2013
It's a reduced function for the purpose of posting it here - it will be enhanced with if statements. Aswell, I would like to know why this does not work.
Re: Returning string of enum -
hiok - 03.08.2013
pawn Код:
enum a {
str[MAX_PLAYER_NAME];
}
new array[MAX_PLAYERS][a];
public OnPlayerConnect(playerid) {
GetPlayerName(playerid, array[playerid][str], MAX_PLAYER_NAME);
}
returnPlayerName(playerid) {
new name[MAX_PLAYER_NAME];
format(name, sizeof(name), "%s", array[playerid][str]);
return name;
}
That would work but creating another variable is a waste of resources - how can I do it without that variable?
Re: Returning string of enum -
Edix - 03.08.2013
can you try formating the array instead? (yes I know it sounds stupid but just give it a go)
Re: Returning string of enum -
hiok - 03.08.2013
Quote:
Originally Posted by Edix
can you try formating the array instead? (yes I know it sounds stupid but just give it a go)
|
I don't quite understand, could you explain that any further?
Re: Returning string of enum -
Edix - 03.08.2013
pawn Код:
returnPlayerName(playerid) {
format(array[playerid][str], MAX_PLAYER_NAME, "%s", array[playerid][str]);
return array[playerid][str];
}
Try this.
Re: Returning string of enum -
hiok - 04.08.2013
Still in need of a proper solution!
Re: Returning string of enum -
RajatPawar - 04.08.2013
pawn Код:
enum a
{
name[MAX_PLAYER_NAME]
}
new array[MAX_PLAYERS][a];
public OnPlayerConnect(playerid)
{
GetPlayerName(playerid, array[playerid][str], MAX_PLAYER_NAME);
}
stock returnNAME_(playerid, const name[], const size = sizeof(name) )
{
return format(name, size, "%s", array[playerid][str];
}
Kind of like the GetPlayerName function of SA-MP
Re: Returning string of enum -
hiok - 04.08.2013
So it's only possible to pass it by reference?