This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Graypup's profile picture

Are global variables actually global?

Started by Graypup, 15 June 2012 - 11:42 PM
Graypup #1
Posted 16 June 2012 - 01:42 AM
Are global variables created in one CC program accessible from another?
MysticT #2
Posted 16 June 2012 - 01:47 AM
Yes, they are stored in the global table, so you can access them from another program. It's not good practice though.

Edit: just checked the shell program, and each shell creates an environment to run the programs, so the variables will be global to the shell that's running the program.
kazagistar #3
Posted 16 June 2012 - 01:54 AM
The os loaded APIs have namespaces, so if you set a global in one of those, it just becomes one of the local attributes of the API's table.

Also note, the global scope applies to functions as well.
Graypup #4
Posted 16 June 2012 - 06:49 PM
OK, fortunately I just read programming in lua, so I actually remember what that means. Anyway, thanks.
Also, is it possible to create truly global variables?
I was intending to create variables for functions that are super-annoying to type the names of.