Advertisement
Plazter

KeyTimer

Sep 29th, 2013
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. -- Made by Plazter and Pizzamanden12---
  2. -- Credit given to: kreezxil for Helping out with the code --
  3. -- Thanks to all on CCForum that tryed to help aswell --
  4.  
  5. local tArgs = {...}
  6.  
  7. if tArgs[1] == nil or tArgs[1] == "help" then
  8. term.clear()
  9. term.setCursorPos(1,1)
  10. print("<program> <side>, you adjust the timer on arrow up/down")
  11. return
  12. end
  13.  
  14.  
  15. local side = tArgs[1]
  16. local tid = 1
  17. local key = 0
  18.  
  19. function testKey()
  20. _, key = os.pullEvent("key")
  21. if key == keys.up then
  22. tid = tid+1
  23. elseif key == keys.down and tid == 1 then
  24. tid = tid+1
  25. print("You have tryed to do the impossible!")
  26. sleep(5)
  27. elseif key == keys.down then
  28. tid = tid-1
  29. end
  30. end
  31.  
  32. function speed()
  33. term.clear()
  34. term.setCursorPos(1,1)
  35. print("Delay is now: ".. tid)
  36. end
  37.  
  38. function timer()
  39. rs.setOutput(side, true)
  40. sleep(0.3)
  41. rs.setOutput(side, false)
  42. sleep(tid)
  43. end
  44.  
  45. while key ~= keys.left do
  46. speed()
  47. -- using the parallel api we should be able to allow the program run all the time
  48. parallel.waitForAny(timer,testKey)
  49. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement