Advertisement
CaptainSpaceCat

Coroutine Testing Center

Dec 13th, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.28 KB | None | 0 0
  1. local slowWrite
  2. local coDone = false
  3. function resetWrite()
  4. slowWrite = coroutine.create(function (str, speed, delay)
  5.   for i = 1, #str do
  6.     local index = 1
  7.     if not coDone then
  8.       write(str:sub(i, i))
  9.       coroutine.yield(1/speed)
  10.     end
  11.   end
  12.   return true, delay
  13. end)
  14. end
  15.  
  16. function blink(speed)
  17.         if not speed then
  18.                 speed = .4
  19.         end
  20.         local a,b = term.getCursorPos()
  21.         uWords(" ", a, b, _, colors.lime)
  22.         coroutine.yield(speed)
  23.         uWords(" ", a, b, _, colors.black)
  24.         coroutine.yield(speed)
  25.     term.setCursorPos(a,b)
  26. end
  27.  
  28. local messages = {
  29. {"WELCOME TO ROBCO INDUSTRIES (TM) TERMLINK", 160, 1},
  30. {"SET TERMINAL/INQUIRE", 30, .75},
  31. {"\nRIT-V300", 30, 1},
  32. {"\nSET FILE/PROTECTION-OWNER:RWED ACCOUNTS.F", 30, 1},
  33. {"SET HALT RESTART/MAINT", 30, .5},
  34. {"\nInitializing Robco Industries(TM) MF Boot Agent", 160, .1},
  35. {"RETROS BIOS", 160, .1},
  36. {"RBIOS-4.02.08.00 52EE5.E7.E8", 160, .1},
  37. {"Copyright 2201-2201 Robco Ind.", 160, .1},
  38. {"Uppermem: 64 KB", 160, .1},
  39. {"Root (5AB)", 160, .1},
  40. {"Maintenance Mode", 160, 1},
  41. {"\nRUN DEBUG/ACCOUNTS.F", 30, 1}
  42. }
  43.  
  44. local cMsg = 1
  45. local writeTimer, blinkTimer
  46.  
  47. function txt()
  48.   term.setCursorBlink(true)
  49.   term.setBackgroundColor(colors.black)
  50.   term.setTextColor(colors.lime)
  51.   term.clear()
  52.   term.setCursorPos(1, 1)
  53.   resetWrite()
  54.   _, length = coroutine.resume(slowWrite, messages[cMsg][1], messages[cMsg][2], messages[cMsg][3])
  55.   writeTimer = os.startTimer(length)
  56.   while true do
  57.     local events = {os.pullEvent()}
  58.     if events[1] == "timer" then
  59.       if events[2] == writeTimer then
  60.         _, length, delay = coroutine.resume(slowWrite, messages[cMsg][1], messages[cMsg][2], messages[cMsg][3])
  61.         if delay then
  62.           writeTimer = os.startTimer(delay)
  63.           cMsg = cMsg + 1
  64.           if cMsg > #messages then
  65.             sleep(delay)
  66.             break
  67.           end
  68.           resetWrite()
  69.           print()
  70.         else
  71.           writeTimer = os.startTimer(length)
  72.         end
  73.       end
  74.     elseif events[1] == "key" or events[1] == "mouse_click" then
  75.       os.cancelTimer(writeTimer)
  76.       coDone = true
  77.       term.setBackgroundColor(colors.black)
  78.       term.clear()
  79.       term.setCursorPos(1, 1)
  80.       break
  81.     end
  82.   end
  83. end
  84.  
  85. txt()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement