Accessing varibles from console [SOLVED]

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
Granamir
Posts: 202
Joined: Wed Jan 07, 2015 7:19 pm

Accessing varibles from console [SOLVED]

Post 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
Last edited by Granamir on Wed Feb 04, 2015 5:08 pm, edited 1 time in total.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Accessing varibles from console

Post 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)
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Granamir
Posts: 202
Joined: Wed Jan 07, 2015 7:19 pm

Re: Accessing varibles from console

Post by Granamir »

Understood
Thank you very much
Post Reply