r/ComputerCraft • • Jan 24 '17

Computercraft code help

The code lies here: http://pastebin.com/FcJcPg3s

2 Upvotes

7 comments sorted by

View all comments

Show parent comments

0

u/[deleted] Jan 25 '17

[deleted]

2

u/dragon53535 Jan 26 '17 edited Jan 26 '17

Global variables DO transfer between files in Lua for as long as the lua shell is running. In the case of CraftOS, global variables exist between all programs in the computer until the computer restarts. The only time this is not applicable is if you change the environment the global variable is declared in.

What I believe you're confused about is persistance, global variables and their values only exist for the execution cycle of the computer. When the computer turns off, whatever value that was stored is gone.

Edit: To sort of just kill the debate: A program is essentially a function being run by the shell. Global variables ignore scope completely, while locals do not. Since each program is a separate function, their locals are not available to each other, but globals which ignore scope entirely are able to be read.

0

u/[deleted] Jan 26 '17

[deleted]

1

u/dragon53535 Jan 26 '17

The feature of globals? Likely something slow as it's faster to have local variables.