Variable name from string?
#1

Let's say i have 5 variables, and i want to change values in them...

pawn Код:
PlayerInfo[playerid][pSomething1];
PlayerInfo[playerid][pSomething2];
PlayerInfo[playerid][pSomething3];
PlayerInfo[playerid][pSomething4];
PlayerInfo[playerid][pSomething5];
How would i do this better and with less lines?

pawn Код:
if(!strcmp(method, "pSomething1", true)) { code for changing pSomething1 }
if(!strcmp(method, "pSomething2", true)) { code for changing pSomething2 }
if(!strcmp(method, "pSomething3", true)) { code for changing pSomething3 }
if(!strcmp(method, "pSomething4", true)) { code for changing pSomething4 }
if(!strcmp(method, "pSomething5", true)) { code for changing pSomething5 }
I curently have much more than only 5 variables and it's a pain to do it like shown above.

So is there a better way? Something like:

pawn Код:
PlayerInfo[playerid][p%s]
So i don't have to have so many if's?

Thank you.
Reply


Messages In This Thread
Variable name from string? - by Whizion - 04.10.2012, 10:53
Re: Variable name from string? - by Roel - 04.10.2012, 10:58
Re: Variable name from string? - by Whizion - 04.10.2012, 11:30

Forum Jump:


Users browsing this thread: 2 Guest(s)