getVariable VS. getZScriptVariable"
Maya001122 (talk | contribs) m (Created page with '{{ZKDevelopersGuidePageHeader}} Variables defined in the namespace can be retrieved by use of the <tt>getVariable</tt> method. On the other hand, variables defined in <tt>zscri…') |
m (correct highlight (via JWB)) |
||
Line 1: | Line 1: | ||
{{ZKDevelopersGuidePageHeader}} | {{ZKDevelopersGuidePageHeader}} | ||
− | Variables defined in the namespace can be retrieved by use of the < | + | Variables defined in the namespace can be retrieved by use of the <code>getVariable</code> method. |
− | On the other hand, variables defined in < | + | On the other hand, variables defined in <code>zscript</code> is part of the interpret that interprets it. They are ''not'' a part of any namespace. In other words, you can ''not'' retrieve them by use of the <code>getVariable</code> method. |
<source lang="xml" > | <source lang="xml" > | ||
Line 12: | Line 12: | ||
</source> | </source> | ||
− | Instead, you have to use < | + | Instead, you have to use <code>getZScriptVariable</code> to retrieve variables defined in <code>zscript</code>. Similarly, you can use <code>getZScriptClass</code> to retrieve classes and <code>getZScriptFunction</code> to retrieve methods defined in <code>zscript</code>. These methods will iterate through all loaded interpreters until the specified one is found. |
− | If you want to search a particular interpreter, you can use the < | + | If you want to search a particular interpreter, you can use the <code>getInterpreter</code> method to retrieve the interpreter first, as follows. |
<source lang="java" > | <source lang="java" > |
Latest revision as of 10:41, 19 January 2022
This documentation is for an older version of ZK. For the latest one, please click here.
Variables defined in the namespace can be retrieved by use of the getVariable
method.
On the other hand, variables defined in zscript
is part of the interpret that interprets it. They are not a part of any namespace. In other words, you can not retrieve them by use of the getVariable
method.
<zscript>
var1 = 123; //var1 belongs to the interpreter, not any namespace
page.getVariable("var1"); //returns null
</zscript>
Instead, you have to use getZScriptVariable
to retrieve variables defined in zscript
. Similarly, you can use getZScriptClass
to retrieve classes and getZScriptFunction
to retrieve methods defined in zscript
. These methods will iterate through all loaded interpreters until the specified one is found.
If you want to search a particular interpreter, you can use the getInterpreter
method to retrieve the interpreter first, as follows.
page.getInterpreter("JavaScript").getVariable("some"); //interpreter for JavaScript
page.getInterpreter(null).getVariable("some"); //interpreter for default language