kikito wrote:Just out of curiosity: what does your script do, and why do you think it takes 10 seconds to run it?
The "heavy script" is an artificial intelligence based on MCTS (http://mcts.ai/). I give, as input, the number of iterations it must do (the more iteration the more accurate are the game theoretic values, so it's more similar to a minimax tree). If the iterations reach 10000, the script takes some seconds to return what move to do. So, I needed to display the move selection screen and, while the human player chooses what to do, in the background the AI algorithm should run without freezing everything. It works quite well putting the
Just make sure to not make the coroutine yield run too often because it can actually slow things down.
Think of it this way. Yielding once might actually take slightly more time than it would to do a few hundred or thousand loops of your for loop. So play around with the timer that counts down to the next yield. You might even get away with setting that loop counter pretty high. Or depending on your code, it might require a much lower number. Play around!
Jasoco wrote:Just make sure to not make the coroutine yield run too often because it can actually slow things down.
Think of it this way. Yielding once might actually take slightly more time than it would to do a few hundred or thousand loops of your for loop. So play around with the timer that counts down to the next yield. You might even get away with setting that loop counter pretty high. Or depending on your code, it might require a much lower number. Play around!
Yes, I already played around a bit, since I noticed that it would become really slow if yielding too much.
Thanks a lot! You pointed me to the right direction!