Returning string of enum
#1

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

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.
Reply
#3

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.
Reply
#4

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?
Reply
#5

can you try formating the array instead? (yes I know it sounds stupid but just give it a go)
Reply
#6

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

pawn Код:
returnPlayerName(playerid) {
    format(array[playerid][str], MAX_PLAYER_NAME, "%s", array[playerid][str]);
    return array[playerid][str];
}
Try this.
Reply
#8

Still in need of a proper solution!
Reply
#9

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

So it's only possible to pass it by reference?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)