331 posts
Posted 20 August 2013 - 06:43 AM
Version Info: 1.56 Client And 1.56 Server
Description of bug: after running my program it seems to break backspacing/deleting characters in the edit program
How To Reproduce: Run this program here
http://pastebin.com/q7vk7hdy then do "edit file" and then write some letters and try to backspace
8543 posts
Posted 20 August 2013 - 10:44 AM
Don't overwrite global variables, specifically the keys table that many programs use to look for things like keys.delete.
Moved to Ask a Pro.
171 posts
Location
Eastern USA
Posted 20 August 2013 - 10:50 AM
keys is already defined, and you're overwriting it with your own keys table. Rename your keys table to something else.
808 posts
Posted 20 August 2013 - 06:43 PM
Or instead of not calling your variable "keys" just make it a local variable. Then it won't overwrite. I'm surprised how uncommon that ever-important "local" keyword is among the code on these forums.
2217 posts
Location
3232235883
Posted 22 August 2013 - 11:37 PM
ah, this useless conversation where everybody posts the same way of fixing the overwrite global problem
http://computercraft...i/Category:APIs <- dont overwrite these
this also includes many other built in apis:
http://www.lua.org/manual/5.1/localization:
bad:
local var=0
for l1=1,100 do
local var=1+var
end
good
local var=0
for l1=1,100 do
var=1+var
end
localized variables only work within their own block and their child blocks
this includes do,for,while,function,etc statements
this is how you localize functions:
local function foo()
same dynamics as variables