Page 1 of 1

[Solved] sleep in threads

Posted: Sat Mar 18, 2017 12:48 am
by SirDust
I was trying threads for the first time, and it appears that love.timer in threads is a nil value, because I get the "attempted to index a nil value" error message whenever I access it.

This means I do not have access to love.timer.sleep for any delays in code execution. Is there another way to do these sorts of delays in threads?

I am aware that I could the "demand" method of channels that are communicating with the main thread, and so have the main thread do all of the sleeping for the other threads, but that would be difficult to set up. I do not want to do this if there is an easier way.

Re: sleep in threads

Posted: Sat Mar 18, 2017 12:53 am
by SirDust
(Also If I am correct that love.timer in threads is a nil value, perhaps that info should be added to the love wiki, especially since the wiki already states what other modules are restricted)

Re: sleep in threads

Posted: Sat Mar 18, 2017 1:39 am
by Sulunia
AFAIK you have to import all love modules you want to use in your threads manually. So, try importing love.timer before actually using it!

Re: sleep in threads

Posted: Sat Mar 18, 2017 1:44 am
by zorg
Sulunia wrote: Sat Mar 18, 2017 1:39 am AFAIK you have to import all love modules you want to use in your threads manually. So, try importing love.timer before actually using it!
love.thread is the only module that gets loaded in a thread automatically, but Sulunia's right; everything else you'll need to require in yourself; for example:

Code: Select all

require 'love.sound'
require 'love.audio'
SirDust wrote: Sat Mar 18, 2017 12:53 am (Also If I am correct that love.timer in threads is a nil value, perhaps that info should be added to the love wiki, especially since the wiki already states what other modules are restricted)
Also from the relevant wiki page: "When a Thread is started, it only loads the love.thread module. Every other module has to be loaded with require." right above the first yellow notice box.

By the way, only love.graphics and love.window is really restricted; everything else should (more-or-less) work.

Re: sleep in threads

Posted: Sat Mar 18, 2017 3:34 am
by SirDust
whoops did not see that. Ok that makes sense, thanks!