166 posts
Location
Don't look behind you..
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..
436 posts
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.
474 posts
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"
378 posts
Location
In the TARDIS
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?
474 posts
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()
1111 posts
Location
Portland OR
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.
378 posts
Location
In the TARDIS
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
166 posts
Location
Don't look behind you..
Posted 27 April 2012 - 06:36 PM
Thanks guys for the help!!!