Altamurenza

LUA Tutorial: Coroutine Usage

Jan 27th, 2018
400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.55 KB | None | 0 0
  1. -- Coroutine Usage
  2. -- https://www.lua.org/pil/9.html
  3.  
  4. -- Main function:
  5. function main()
  6.     Wait(450)
  7.    
  8.     -- Min and Max number:
  9.     local Min,Max = 1,10
  10.     -- Number:
  11.     Number = coroutine.create(function()
  12.         for n = Min,Max + 1 do
  13.             -- Print:
  14.             TextPrintString(tostring(n),1,2)
  15.             -- Reset:
  16.             if n == Max then
  17.                 n = Min - 1
  18.             end
  19.            
  20.             -- Suspend:
  21.             coroutine.yield()
  22.         end
  23.     end)
  24.     -- Process:
  25.     while true do
  26.         if IsButtonBeingPressed(3,0) then
  27.             -- Resume:
  28.             local IsValid,Select = coroutine.resume(Number)
  29.         end
  30.        
  31.         Wait(0)
  32.     end
  33. end
Add Comment
Please, Sign In to add comment