Jump to content




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



  • You cannot reply to this topic
4 replies to this topic

#1 jay5476

  • Members
  • 289 posts

Posted 20 August 2013 - 05: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

#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 20 August 2013 - 09: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.

#3 electrodude512

  • Members
  • 167 posts
  • LocationEastern USA

Posted 20 August 2013 - 09:50 AM

keys is already defined, and you're overwriting it with your own keys table. Rename your keys table to something else.

#4 ElvishJerricco

  • Members
  • 803 posts

Posted 20 August 2013 - 05: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.

#5 PixelToast

  • Signature Abuser
  • 2,265 posts
  • Location3232235883

Posted 22 August 2013 - 10: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





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users