A very Tough Question
#1

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
Reply
#2

"new value = valstr(str, var);" ?
Reply
#3

have a look at the GVar Plugin
heres your code as example:
pawn Код:
SetGVarInt("var",88,0);
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
Reply
#4

Quote:
Originally Posted by Babul
Посмотреть сообщение
have a look at the GVar Plugin
heres your code as example:
pawn Код:
SetGVarInt("var",88,0);
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.
Reply
#5

Yes, you are totally correct.
Reply
#6

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.
Reply
#7

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..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)