So lets say I had a script:
1 | local function a() |
2 | wait(math.random( 1 , 5 )) |
3 | print ( "This is a function" ) |
4 | end ) |
5 |
6 | while true do |
7 | a() |
8 | wait() |
9 | end |
With this script, it would wait until our function, a
, is complete before running it again. Is there any way that I could make the while loop "ignore" the wait inside the function, and do the next thing immediately?
Yes, you use the coroutine.wrap
method to do this!
1 | local function a() |
2 | wait(math.random( 1 , 5 )) |
3 | print ( "This is a function!" ); |
4 | end |
5 |
6 | while true do |
7 | coroutine.wrap(a)() |
8 | wait() |
9 | end |