You have the following four ways and scopes in which to declare variables given a script with name some.script
:
EXAMPLE 1
go.property("foobar", 123)
function init(self)
print(self.foobar)
end
foobar
is exposed in the editor when selecting some.script in the outline. foobar
is unique to each game object instance with some.script attached. Accessible via self.foobar
and go.get("some/url/", "foobar")
EXAMPLE 2
function init(self)
self.foobar = 123
end
foobar
is unique to each game object instance with some.script attached. Accessible via self.foobar
.
EXAMPLE 3
local foobar = 123
function init(self)
print(foobar)
end
foobar
is shared between all script instances of type some.script.
EXAMPLE 4
-- in some.script
foobar = 123
-- in some_other.script
function init(self)
print(foobar)
print(_G.foobar)
print(_G["foobar"])
end
foobar
is declared on the global table _G and accessible from everywhere.