Attract-Mode Support Forum
Attract-Mode Support => Scripting => Topic started by: iOtero on August 30, 2018, 11:57:01 AM
-
What is the difference between this code:
::fe.add_transition_callback(this, "on_transition");
and this one:
fe.add_transition_callback(this, "on_transition");
-
According to 3.0 docs:
Global variables are stored in a table called the root table. Usually in the global scope the environment object is the root table, but to explicitly access the global table from another scope, the slot name must be prefixed with '::' (::foo).
exp:= '::' id
For instance:
function testy(arg)
{
local a=10;
return arg+::foo;
}
accesses the global variable 'foo'.
However (since squirrel 2.0) if a variable is not local and is not found in the 'this' object Squirrel will search it in the root table.
function test() {
foo = 10;
}
is equivalent to write
function test() {
if("foo" in this) {
this.foo = 10;
}else {
::foo = 10;
}
}
-
so :: it indicates a global variable ... interesting, thanks.
-
so :: it indicates a global variable ... interesting, thanks.
Global variable must be set as such, but can be accessed with or without if no local variable has same name.