Search results
Aug 14, 2013 · If you use or set a variable without using local, it will try and use or set a global variable which can be used and modified by other scripts. Although it likely won't be an issue when you are using ComputerCraft, it is advisable to use local variables and functions when possible, so they will not be unintentionally edited by other functions ...
Mar 25, 2014 · The "type" functions will give you a string with the type of variable you give it. In this case, if the variable is not a string, it will run "return". Return will be described in more detail later in this tutorial, but for now we only need to know it ends the function, so any code after it will not be run.
A local function is similarly defined using local (e.g. local function something ()), and a global is without the 'local' keyword. The problem is you need to ensure that the global function is 'registered' in the globals. The best way to do this is to run the program file it is constructed in. Then, you should be able to access it in any other ...
Mar 21, 2014 · str = “String theory, get it” -- This is a global string variable local pauline = 9 --A number variable --Now I am going to define a function, using a new keyword function function foo(bar) print(bar) –- [[bar is a parameter, which can be any type of variable. This function will attempt to print that parameter]] end -- end is another keyword.
Dec 22, 2019 · This is a short tutorial / theory session regarding functions. Writing functions is almost like writing a game engine. Functions can easily simplify and shorten your code. And make it faster to complete while also making future programs faster to write. Function sets like that are also known as an APIs.
This will set up a list variable named args that is a list of all of the arguments that have been added to the program. For example: myprogram foo 30 bar. will give you an args list with a length of 3 that contains: ["foo", "30", "bar"] You'd access the different elements like you would any other list, for example foo[2] would give you "30".
People also ask
Should I use local variables or functions in Computercraft?
Should I use a local variable or a global variable?
Do I need to write a local variable?
What are the rules of Computercraft coding?
What does 'local' mean in JavaScript?
When should variables be defined?
Jun 11, 2024 · Use local variables as much as possible, including local functions. You should avoid global variables as much as possible, as they are slower, aren't automatically garbage collected, and can cause funky errors when other code uses the same variable name.