During a script, if you have something that you needed to loop in a separate loop to another loop which is currently active, I'd have thought a function would be a good idea, however with normal functions, after being called they continue to take the "scripts time" rather than executing the function simultaneously with the code around it.
For example, as the code below suggests, it has a look, followed by a function with a loop, which the script will execute this function and THEN move onto the next loop. Ideally i'd like the function to continue while the script plays out.
Other than making the function another script, (meaning I want to keep it in the same script without global or anything) is there any other way to go about this?
function WastingTime() local number=0 for i=1,10 do wait(1) number=number+1 print("Waiting" .. number) end end wait(1) for i=1,10 do wait(1) print("Wait") end WastingTime() for i=1,10 do wait(1) print("Wait2") end
-Thank you
For running multiple lines of code you will need to look a Threading in short the code block will continue to run both functions.
Other links that may help:- Coroutine_manipulation
Please see this question:
https://scriptinghelpers.org/questions/11710/2-functions-at-a-time
Yes, you can do this, but most of the time it will not be the best solution
As a simple example, two Script objects will run at the same time. Each Script object is given its own "thread", or, as Lua calls it, coroutine (routine being a piece of a program and co indicating that multiple are working together as in coworker)
A coroutine is similar to a thread (in the sense of multithreading): a line of execution, with its own stack, its own local variables, and its own instruction pointer; but sharing global variables and mostly anything else with other coroutines.
See Also: https://scriptinghelpers.org/questions/11836/can-one-script-run-many-items for more complicated comparison of with coroutine and without