64 posts
Location
Finland
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
3057 posts
Location
United States of America
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
957 posts
Location
Web Development
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
1140 posts
Location
Kaunas, Lithuania
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")
64 posts
Location
Finland
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?
3057 posts
Location
United States of America
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.
64 posts
Location
Finland
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.