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

Wait until keypress

Started by lare290, 20 August 2015 - 07:15 PM
lare290 #1
Posted 20 August 2015 - 09:15 PM
How to best make program wait for key press and then go back to do what it should? I'm making password-protected vault lock and it would not be nice if door locked behind you because of timer.

You might better understand what I need if you read my code:

os.pullEvent = os.pullEventRaw
while true do
   term.clear()
   term.setCursorPos(1, 1)
   print("Please Enter Password:")
   input = read ("*")
   if input == "Examplepassword" then
	  redstone.setOutput("down", true)
	  ___NORMALLY TIMER WOULD BE HERE___
	  redstone.setOutput("down", false)
   end
end
Edited on 20 August 2015 - 07:15 PM
KingofGamesYami #2
Posted 20 August 2015 - 09:23 PM

os.pullEvent( "key" )

Edit: Bwahahah I'm the ultimate ninja :P/>
Edited on 20 August 2015 - 07:24 PM
HPWebcamAble #3
Posted 20 August 2015 - 09:23 PM
You'd use 'os.pullEvent()', you might want to read up on that.

But in the meantime, here's a simple piece of code for you:

repeat --# Executes this code until...
  local event,key = os.pullEvent("key")
until key == keys.enter --# Change the 'keys.enter' to what you'd like

Edit - Ninja'd :ph34r:/>
Edited on 20 August 2015 - 07:24 PM
MKlegoman357 #4
Posted 20 August 2015 - 09:24 PM
The simplest way of waiting for a keypress would be to simply pull a key event:


os.pullEvent("key")
lare290 #5
Posted 20 August 2015 - 09:35 PM

os.pullEvent( "key" )

Edit: Bwahahah I'm the ultimate ninja :P/>
so where would I put this? in the place of timer?
KingofGamesYami #6
Posted 20 August 2015 - 10:01 PM
That line literally pauses until the user presses any key. So put it wherever you want to pause.
lare290 #7
Posted 20 August 2015 - 10:31 PM
That line literally pauses until the user presses any key. So put it wherever you want to pause.
Alright, thanks.