PDA

View Full Version : String to variable


whitedragon
10/10/2011, 07:33 PM
Hello i just wondering how to make
new string[64];
format(str,sizeof(str),"Variable1");
to variable
formated str will be variable that then i call
Info[str] it give there Variable1.
Like it search for Info[Variable1] not Info[str]

FireCat
10/10/2011, 07:36 PM
Can you explain a bit better please?

Kush
10/10/2011, 08:01 PM
Can you explain a bit better please?

I'm assuming he's wanting to call string in different areas within his code.


new string[5+1] = "Debug";
print(string);

grand.Theft.Otto
10/10/2011, 08:32 PM
Ah, something like this for example ? :

format(str,sizeof(str),"Grams Of Drugs Left: %d",PlayerInfo[playerid][Grams]);

whitedragon
10/10/2011, 08:52 PM
I mean:
new str[64];
enum stuff{
Variable1,
Variable2
}
new Info[stuff];

// some public
switch(x)
{
case 1: format(str,sizeof(str),"Variable1");
case 2: format(str,sizeof(str),"Variable2");
}
Info[str] // he should look Variable1 but str

Vince
10/10/2011, 09:06 PM
If I understand correctly, then what you're trying to do is not possible. At least not in this way. Something like this should work though:

new idx;
switch(x)
{
case 1: idx = stuff:Variable1;
case 2: idx = stuff:Variable2;
}
Info[idx] = /* your stuff */