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

Save Variable in Memory?

Started by Hayden_Almeida, 30 April 2016 - 11:37 PM
Hayden_Almeida #1
Posted 01 May 2016 - 01:37 AM
Hello guys.

There's a way to save a variable globally in one computer?
One Example:

I have one program called "test" , this program have this lines:

Variable_2 = "Maria"

Now, in other program, can i call the variable in the program "test" ? Like:

if Variable_2 == "Maria" then

Etc…
Anavrins #2
Posted 01 May 2016 - 01:41 AM
Yes, simply omit the "local" keyword when declaring variables.
lieven121 #3
Posted 01 May 2016 - 01:46 AM
yes if you do this it will work unless you reboot the only way you can keep data from rebooting is writing it in the memory
Hayden_Almeida #4
Posted 01 May 2016 - 01:50 AM
yes if you do this it will work unless you reboot the only way you can keep data from rebooting is writing it in the memory

And if i use the the

os.pullEvent = pullEvent
to terminate the "startup" program. It losts the memory?
TYKUHN2 #5
Posted 01 May 2016 - 02:18 AM
It should be mentioned that 90% of all ways to run a program WON'T keep the variable between programs although there IS a way. Check os.run.

os.pullEvent = pullEvent does nothing by default either except causing programs to crumble to tiny little pieces as they desperately try to get events and definitely won't terminate the "startup" program.

Edit: Example code

File 1:

tEnv = {}
os.run(tEnv, "File_2")
os.run(tEnv, "File_3")
print(tEnv["test"])

Outputs: "Hello Forums!"

File 2:

test = "I am a test variable!"
print(test)

Outputs: "I am a test variable!"

File 3:

print(test)
test = "Hello Forums!"
print(test)

Output 1: "I am a test variable!""Hello Forums!"
Output 2: "Hello Forums!"
Edited on 01 May 2016 - 12:25 AM