A very Tough Question -
[MM]RoXoR[FS] - 20.07.2012
How can I get variable value from String?
Suppose, I have
pawn Код:
new var = 88;
new str[] = "var";
new value = VariableValue(str);
//Now value should also be 88
Re: A very Tough Question -
Andi_Evandy - 20.07.2012
"new value = valstr(str, var);" ?
Re: A very Tough Question -
Babul - 20.07.2012
have a look at the
GVar Plugin
heres your code as example:
a gvar can be named - even better: to access the named variables, you may use any string:
pawn Код:
new string[16];
format(string,sizeof(string),"var");//feel free to add %d with ,playerid
new result=GetGVarInt(string,0);//now result contains 88
Re: A very Tough Question -
[MM]RoXoR[FS] - 20.07.2012
Quote:
Originally Posted by Babul
have a look at the GVar Plugin
heres your code as example:
a gvar can be named - even better: to access the named variables, you may use any string:
pawn Код:
new string[16]; format(string,sizeof(string),"var");//feel free to add %d with ,playerid new result=GetGVarInt(string,0);//now result contains 88
|
No, No , I actually dont need this.
I am making an include, hence I wont have any access to other script and variables.
Re: A very Tough Question -
[MM]RoXoR[FS] - 20.07.2012
Yes, you are totally correct.
Re: A very Tough Question -
[MM]RoXoR[FS] - 20.07.2012
Quote:
Originally Posted by [HLF]Southclaw
That can't be done, when you compile the code, variable names just become addresses, the labels you give them in the source are simply just that, labels, for humans to read.
Public functions are addressed by strings however. But any normal function is a memory address just like variables.
Why are you trying to do this anyway?
|
I saw people doing this in many languages. Like c++,c#, php, vb etc.
Why not pawn
@Y-Less Can You tell the better way.
Re: A very Tough Question -
[MM]RoXoR[FS] - 20.07.2012
I want that player/scripter should be able to pass his variable name to my include stock.
In my include, I would like to use his variable name to do the recquired operation.
This way even if he do like
pawn Код:
MyFunction("pInfo[tid][Kills]");
//In My include
MyFunction(str[])
{
new bool:found;
if(strfind(seq,"tID",true,0) == -1) found = false;
else found = true;
for(new tid = 0;tid<MAX_PLAYERS;++tid){
if(!IsPlayerCOnnected(tid) continue;
else
{
//A function or something so that now str becomes pInfo[tID][Kills].. instead of string or probably
//str stores the value of pInfo[tID][Kills]
//Do operation here
}
}
}
Scripter should be able to pass any variable name they want, like money, Kills, Deaths etc..
First, I though of recording deaths ,kills, money etc of a player in my include.
But, I though it would be good if user could send any of his variable..