Jump to content




Wait until keypress


6 replies to this topic

#1 lare290

  • Members
  • 53 posts
  • LocationFinland

Posted 20 August 2015 - 08: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 by lare290, 20 August 2015 - 08:15 PM.


#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 20 August 2015 - 08:23 PM

os.pullEvent( "key" )

Edit: Bwahahah I'm the ultimate ninja :P

Edited by KingofGamesYami, 20 August 2015 - 08:24 PM.


#3 HPWebcamAble

  • Members
  • 933 posts
  • LocationWeb Development

Posted 20 August 2015 - 08: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 by HPWebcamAble, 20 August 2015 - 08:24 PM.


#4 MKlegoman357

  • Members
  • 1,170 posts
  • LocationKaunas, Lithuania

Posted 20 August 2015 - 08:24 PM

The simplest way of waiting for a keypress would be to simply pull a key event:

os.pullEvent("key")


#5 lare290

  • Members
  • 53 posts
  • LocationFinland

Posted 20 August 2015 - 08:35 PM

 KingofGamesYami, on 20 August 2015 - 08:23 PM, said:

os.pullEvent( "key" )

Edit: Bwahahah I'm the ultimate ninja :P
so where would I put this? in the place of timer?

#6 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 20 August 2015 - 09:01 PM

That line literally pauses until the user presses any key. So put it wherever you want to pause.

#7 lare290

  • Members
  • 53 posts
  • LocationFinland

Posted 20 August 2015 - 09:31 PM

 KingofGamesYami, on 20 August 2015 - 09:01 PM, said:

That line literally pauses until the user presses any key. So put it wherever you want to pause.
Alright, thanks.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users