Getting numeric value from a variable name formatted into a string
#4

You can stringify it by placing a hashtag in front of it (utilises the preprocessor):
PHP код:
#include <a_samp>
enum E_PLAYER_DATA {
    
    
pAdmin,
    
pLevel
};
new 
PlayerInfo[MAX_PLAYERS][E_PLAYER_DATA];
main() {
    new
        
playerid 10
    
;
    
Display_Data(playeridpAdmin#pAdmin);
    
Display_Data(playeridpLevel#pLevel);
}
Display_Data(playeridE_PLAYER_DATA:enumeratorstringified[]) {
    new 
string[128];
    
format(string,sizeof(string),"The value of %s is %i."stringifiedPlayerInfo[playerid][enumerator]);
    print(string);
    return 
true;

prints:
Код:
[04:57:52] The value of pAdmin is 0.
[04:57:52] The value of pLevel is 0.
Using #enumerator inside the function doesn't seem to work because it stringifies what you put after it, hence why I do it in the function call. But at that point, you could just do "pLevel" and stuff.

That's what I understand from your examples.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 3 Guest(s)