Checking for variables in an enum -
introzen - 19.03.2016
Hello! Long time no see. I've just started scripting again after 3-4 years off this forum.
Now to my question! Is there a way to check for a parameter in the 2:nd dimension of an enum?
Example:
pawn Код:
enum pInfo {
  pAdmin,
  pLevel,
  pMoney,
  pName[MAX_PLAYER_NAME]
}
new PlayerInfo[MAX_PLAYERS][pInfo];
How do I loop through PlayerInfo[] and check if pAdmin/pLevel etc. is actually in the enum? Like this:
Tried:
pawn Код:
format(string, sizeof(string), "Requested playerinfo (%s) does not exist.", info);
for(new i=0; i < sizeof(PlayerInfo[]); i++) {
    if(sscanf(PlayerInfo[], "s", info)) return SendErrorMessage(playerid, string);
  }
Full command:
pawn Код:
CMD:setinfo(playerid, params[]) {
  new string[128], id, info[32], level[128];
  if(PlayerInfo[playerid][pAdmin] < 4) return SendInvalidMessage(playerid);
  if(sscanf(params, "uss", id, info, level)) return SendSyntaxMessage(playerid, "/setinfo <playerid/partofname> <pInfo> <string/int>");
  format(string, sizeof(string), "Requested playerinfo (%s) does not exist.", info);
  for(new i=0; i < sizeof(PlayerInfo[]); i++) {
    if(sscanf(PlayerInfo[], "s", info)) return SendErrorMessage(playerid, string);
  }
  format(string, sizeof(string), "PlayerInfo[%s][%s] is set to %s", PlayerName(id), info, level);
  SendInfoMessage(playerid, string);
  PlayerInfo[id][info] = level;
  return 1;
}
The problem is probably obvious, but I can't figure it out.
Thankfull for any help.
Re: Checking for parameter in an enum -
Vince - 19.03.2016
Names of variables are not string. When code is compiled, names of variables and function are translated into memory addresses and the original names are irreversibly lost. This is also the reason why decompilers can never retrieve the code that was originally written, replacing function and variable names with generic terms such as var87 or sub_003c7f.
What you're trying to achieve is impossible.
Re: Checking for parameter in an enum -
introzen - 19.03.2016
Quote:
Originally Posted by Vince
Names of variables are not string. When code is compiled, names of variables and function are translated into memory addresses and the original names are irreversibly lost. This is also the reason why decompilers can never retrieve the code that was originally written, replacing function and variable names with generic terms such as var87 or sub_003c7f.
What you're trying to achieve is impossible.
|
Thank you for clarifying that. Is there another way that I can actually achieve this without checking all the parameters manually? Like:
pawn Код:
if(info == "pAdmin")
if(info == "pLevel")
Because that would just be a ridiculous pain in the a*s.
Re: Checking for parameter in an enum -
IzadorO - 19.03.2016
Quote:
What you're trying to achieve is impossible.
|
You can't.
Re: Checking for variables in an enum -
introzen - 20.03.2016
As a workaround, would it be possible to directly insert that data via SQL and reloading the player properties?
I can't see reason why that would not be possible.
Re: Checking for variables in an enum -
introzen - 23.03.2016
Solved this by updating the variable inside the SQL database, and reloading the character array from the database.