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

[Question]Some newbei Questions..

Started by Teraminer, 19 April 2012 - 04:52 PM
Teraminer #1
Posted 19 April 2012 - 06:52 PM
So I have seen (error) and (local) in some peoples programs/Apis/BlahBlahBlah and I want to know, what local is used for and why error insted of print/write..
OmegaVest #2
Posted 19 April 2012 - 06:59 PM
Local refers to whether or not the variable gets dumped when the program finishes. Otherwise, the bios stores the values after the program terminates.

For example, if you have a turtle that stores its location in a global variable, then it will always know those variables. x will always equal x until otherwise changed.

Local, on the other hand, is only accessible from that program. So local x will be forgotten as soon as the program ends, and a new x will be needed to call it once more.


I actually do not have any experience with error catching, but I assume that is what the "error" tag is for.
cant_delete_account #3
Posted 19 April 2012 - 07:47 PM
The error(), is simply to exit the program. If someone has error("Message Here"), it will print: "filename:lineerror()ison: Message Here"
Wolvan #4
Posted 19 April 2012 - 08:37 PM
You can make custom error messages and terminate the program? That's cool. Can you change the format to only show the message?
cant_delete_account #5
Posted 19 April 2012 - 09:29 PM
You can make custom error messages and terminate the program? That's cool. Can you change the format to only show the message?
Yeah, just do:

print("Message Here")
error()
Luanub #6
Posted 19 April 2012 - 10:16 PM
Keep in mind that using local vars is the preferred method. Using globals is considered bad coding practice. If program a uses a global named x, and program b also uses a global named x they will conflict and cause some pretty interesting issues.
Wolvan #7
Posted 20 April 2012 - 03:34 PM
Keep in mind that using local vars is the preferred method. Using globals is considered bad coding practice. If program a uses a global named x, and program b also uses a global named x they will conflict and cause some pretty interesting issues.
It is not always bad if for eample you want to use the same var on btoh with the same data
Teraminer #8
Posted 27 April 2012 - 06:36 PM
Thanks guys for the help!!!