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

Local Variables

Started by Smiffy, 06 May 2012 - 08:21 PM
Smiffy #1
Posted 06 May 2012 - 10:21 PM
Hello! This is just a quick suggestion, called Local Variables.

Basically, these are variables (just like in programs) that can be accessed by all programs on a computer or disk..

A local variable would be stored on a computer or disk, so the other programs could use the same variable instead of merging the 2 programs together. These variables can be changed by programs.

I have thought up of some basic code to access or change the variables:

createLocalVariable("Dir","NAME")
Example:
a = 2+2
if a == 4 then
createLocalVariable("/","Pwn")
end

setLocalVariable("Dir","NAME","VALUE")
Example:
b = 3-1
if b == 2 then
setLocalVariable("/",Pwn","1337")
end

getLocalVariable("Dir","NAME")
Example:
if program.getLocalVariable("/","Pwn") == "1337" then
print("Epic!")
end


Dir means the Directory. You can state what program or cd you want it in. Saying "createLocalVariable("/startup","New") would put a Local variable in the startup program named "New". This variable would be part of the program, and would be copied along with the startup program if moved.

NAME is the name of the Variable, and Value is the value.. of course…


Also, there would be a new program to view the Local Variables in the system, and where they are.

LocalVariables would show a list of all the current Variables in the system. Maybe saying "LocalVariables delete/add "Dir" " would add or delete the Local Variables.
digpoe #2
Posted 06 May 2012 - 10:26 PM
this already exists, like this:

local var1
if var1 == var2 then
do stuff
end


but, if you did somthing like this:

function hi()
local var1
if var1 == var2 then
do stuff
end
end


var1 wouldn't be able to be used outside of the function.
Advert #3
Posted 06 May 2012 - 10:39 PM
I don't think this will happen. You can create files that contain these computer specific variables.

It'd also be wise to check if the name you've chosen is already in use, to prevent confusion.