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

[Cc1.56][Ssp/smp]Cant Backspace/delete Characters After Running My Program

Started by jay5476, 20 August 2013 - 04:43 AM
jay5476 #1
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
Lyqyd #2
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.
electrodude512 #3
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.
ElvishJerricco #4
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.
PixelToast #5
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