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

Inserted key in read

Started by DeclipZ, 04 April 2015 - 05:10 PM
DeclipZ #1
Posted 04 April 2015 - 07:10 PM
When I use event "key" that button what I pressed automatically writing in field of read. How to fix it?
Lyqyd #2
Posted 04 April 2015 - 07:13 PM
Please post your code.
DeclipZ #3
Posted 04 April 2015 - 07:14 PM

function presets(atStart)
repeat
  clr(colors.lightBlue)
  centerText("x","Run OS at start?",(YSize/2)-2,colors.white)
  centerText("xy","(Y/N)",nil,colors.white)
  local event, key = os.pullEvent("key")
  if key == keys.y then
    atStart = true
  elseif key == keys.n then
    atStart = false
  end
until (key == keys.y) or (key == keys.n)
clr(colors.lightBlue)
centerText("x","Enter computer name:",(YSize/2)-2,colors.white)
term.setCursorPos(5,YSize/2)
os.setComputerLabel(read())
installingAll(atStart)
end
Edited on 04 April 2015 - 05:14 PM
HPWebcamAble #4
Posted 04 April 2015 - 07:20 PM
When I use event "key" that button what I pressed automatically writing in field of read. How to fix it?

Thats because hitting a letter fires two events, your if statment only checks for one.

You need to catch any stray 'char' events
Stick this code after the repeat until loop and before you call the 'read' function:


os.startTimer(0.1) --# If there weren't any stray char events, this will make sure the code doesn't freeze up
os.pullEvent()
DeclipZ #5
Posted 04 April 2015 - 07:24 PM
You need to catch any stray 'char' events
Thank you! You helps me :)/>