Page 1 of 1

Accessing varibles from console [SOLVED]

Posted: Tue Feb 03, 2015 3:30 pm
by Granamir
Hi everyone,
i'm trying to debug some script i did, that doesn't work properly, and i found that i cannot access variable from console.
Beeing specific:
access to external file form a script entity
generate some global variables, not in a function
then use those variables in some functions
some function works fine some other don't
so i tryed to acces variable from console and i always get nil, even for those variables that are obviously working

anyone knows why this thing happens?
thank you

Re: Accessing varibles from console

Posted: Tue Feb 03, 2015 7:34 pm
by minmay
You cannot modify the global environment in Grimrock. Variables declared in a ScriptComponent outside of any block are not global, they are just permanent fields of that ScriptComponent. So if you have the following in a ScriptComponent:

Code: Select all

stuff = "cows"
function doSomething()
  print(stuff)
end
then running the following code in the console will print nil twice:

Code: Select all

print(stuff)
print(doSomething)
Instead you need to reference them like this:

Code: Select all

print(script_entity_1.script.stuff)
print(script_entity_1.script.doSomething)

Re: Accessing varibles from console

Posted: Wed Feb 04, 2015 3:16 pm
by Granamir
Understood
Thank you very much