Advertisement
guitarplayer616

SpaceTEST

May 21st, 2015
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.58 KB | None | 0 0
  1. term.setBackgroundColor(colors.black)
  2. term.clear()
  3. rednet.open("back")
  4. term.setCursorPos(1,1)
  5.  
  6. print("welcome to spaceteeeeeem")
  7. print("que snazzy intro music")
  8.  
  9. --host/join
  10.  
  11. --shell.run("host/join")
  12.  
  13. --ping each other, make sure connection is stable
  14.  
  15. --send = rednet.send(to the other player)
  16. --recieve =
  17.  
  18. keys = {"q","w","e","r","t","y","u","i","o","p","a","s","d","f","g","h","j","k","l","z","x","c","v","b","n","m"}
  19. correct = 0
  20.  
  21. function timeRemaining()
  22.   timer1,timer2 = os.pullEvent("alarm")
  23.   return true
  24. end
  25.  
  26. function sending()
  27.   event, character = os.pullEvent("char")
  28.   return true
  29. end
  30.  
  31. function receiving()
  32.    sID, message = rednet.receive()
  33.    return true
  34. end
  35.  
  36.  
  37.   complete = false
  38.   r = math.random(1,26)
  39.   task = tostring(keys[r])
  40.   print("Press "..task)
  41.   host = true
  42.   local rem = 21
  43.   local k = os.time() + 0.02
  44.   if k >= 18000 then
  45.     k=k-18000
  46.   end
  47.   os.setAlarm(k)
  48.   while not complete do
  49.     event, character, message, timer1, timer2 = nil,nil,nil,nil,nil
  50.     parallel.waitForAny(sending,receiving,timeRemaining)
  51.     print(timer1)
  52.     if timer1 == "alarm" then
  53.     rem = rem - 1
  54.       if rem == 0 then
  55.         textutils.slowPrint("Critical Failure")
  56.         error()
  57.       end
  58.       print("Time Remaining: " .. rem)
  59.     end
  60.     if event then
  61.       print(character)
  62.       rednet.broadcast(character)
  63.     end
  64.     if message then
  65.       print(message)
  66.       if message == task then
  67.         print("Correct")
  68.         correct = correct + 1
  69.         complete = true
  70.       else
  71.         print("Incorrect")
  72.       end
  73.     end
  74.   end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement