variable name as string

Posted By: FcoElizalde

variable name as string - 04/12/10 17:03

Hi everyone,
I there a way to turn the content of a string to the name of a variable and read the content of the variable as the number?

Im looking at this to a for() function:
for example:

for(c=1; c<npc.skill33; c++)
{
str_cpy(ent_skill,"npc.skill");
i=20+c;
str_for_num(skill_n,i);
str_cat(ent_skill,skill_n);

temp=(content of the variale named as the content of the string"ent_skill"
}

or if this isnt possible, could someone tell me another way to achieve a similar result, the idea is to read trough a list in an array without writing all the instruction for each member.

Thanks in advance.
Posted By: Nicotin

Re: variable name as string - 04/12/10 17:38

If I remember it right there should be a function called "var_for_name(STRING* name);" which gives back the pointer to the Variable.
Try this.
Posted By: Tempelbauer

Re: variable name as string - 04/12/10 17:42

http://www.conitec.net/beta/var_for_name.htm
Posted By: FcoElizalde

Re: variable name as string - 04/12/10 17:49

Okay I dont get it, but, this function returns a pointer to a string?

I need to read a var with the name of the content of the string, not the other way around.

Ok ok, if it doesnt contain a "=", then the string transforms to the result right?
Then with str_clip I can cut the name and the "=", getting only the value
And with str_to_num I get the result. ok

thanks for the help guys
Posted By: FcoElizalde

Re: variable name as string - 04/12/10 23:41

Sorry to bother again, but it appears I didnt get it right, because i cant get var_for_name to work.

Anyone there can help me by scripting an example, in the manual theres only 1 line of code:
var_for_name("camera.clip_far = 20000");

Actualy nevermind, my mistake:
This only works with global variables, I was using locals.
It appears this doesnt work with arrays too.
Thanks again.
© 2024 lite-C Forums