Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Var value from var name (https://forums.graalonline.com/forums/showthread.php?t=134261886)

0PiX0 01-29-2011 10:17 AM

Var value from var name
 
PHP Code:

//#CLIENTSIDE
public function getVarFromName(varname) {
  if (
varname.pos(".") == -1) return -1;
  
temp.tokens varname.tokenize(".");
  
temp.objvar = new TStaticVar();
  
temp.objvar.copyfrom((@temp.tokens[0]));
  return 
getSubObj(temp.objvartemp.tokens.subarray(1temp.tokens.size() - 2)).(@temp.tokens[temp.tokens.size() - 1]);
}

public function 
getSubObj(obj,subobjstrarray) {
  if (
subobjstrarray.size()) return getSubObj(obj.(@subobjstrarray[0]), subobjstrarray.subarray(1subobjstrarray.size() - 1));
  else return 
obj;


In 'getVarFromName', the function returns -1 if the input string does not have an object prefix. I would like to return a variable that does not have an object prefix but I am having trouble figuring out how to do so.

this.(@"name"), since there is an object prefix, gives me the correct result. (The name of the weapon)

(@"mousescreenx") gives me 'mousescreenx' as a string.

Is there a solution this problem?

fowlplay4 01-29-2011 10:19 AM

Try makevar:

PHP Code:

//#CLIENTSIDE
function onCreated() {
  echo(
makevar("mousescreenx")); // echos pixel position of mouse on screen


Other makevar example..

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
temp.really.long.var.something "HA";
  
temp.start "temp.really.long.";
  
temp.value makevar(temp.start "var.something");
  echo(
temp.value); // echos "HA"



0PiX0 01-29-2011 10:30 AM

Thanks. :)

fowlplay4 01-29-2011 10:36 AM

What are you doing that requires that functionality though?

Off the top of my head I can only see myself using it in dynamic commands (I.e: /echovar varname).

0PiX0 01-29-2011 10:45 AM

Quote:

Originally Posted by fowlplay4 (Post 1626426)
What are you doing that requires that functionality though?

Nothing in particular. I see no documentation on makevar, and I did not know it existed. So I recreated it for scripting practice and any possible future use.

Deas_Voice 01-29-2011 09:59 PM

i've never used makevar myself, may i ask what's the difference?
PHP Code:

makevar("this.foo_bar") = "var"

or
PHP Code:

this.(@"foo_bar") = "var"

just for the sake of future reference'

cbk1994 01-29-2011 10:37 PM

Quote:

Originally Posted by Deas_Voice (Post 1626497)
i've never used makevar myself, may i ask what's the difference?
PHP Code:

makevar("this.foo_bar") = "var"

or
PHP Code:

this.(@"foo_bar") = "var"

just for the sake of future reference'

There is essentially no difference except that sometimes you can't use the second example and have to use makevar (I think variables that don't have a prefix/object?). Avoid makevar if possible.


All times are GMT +2. The time now is 02:51 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.