[Solved] sleep in threads

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
SirDust
Prole
Posts: 15
Joined: Sat Feb 11, 2017 12:53 am

[Solved] sleep in threads

Post 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.
Last edited by SirDust on Fri Aug 11, 2017 12:29 am, edited 1 time in total.
User avatar
SirDust
Prole
Posts: 15
Joined: Sat Feb 11, 2017 12:53 am

Re: sleep in threads

Post 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)
User avatar
Sulunia
Party member
Posts: 203
Joined: Tue Mar 22, 2016 1:10 pm
Location: SRS, Brazil

Re: sleep in threads

Post 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!
Don't check my github! It contains thousands of lines of spaghetti code in many different languages cool software! :neko:
https://github.com/Sulunia
User avatar
zorg
Party member
Posts: 3468
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: sleep in threads

Post 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.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
SirDust
Prole
Posts: 15
Joined: Sat Feb 11, 2017 12:53 am

Re: sleep in threads

Post by SirDust »

whoops did not see that. Ok that makes sense, thanks!
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Semrush [Bot] and 2 guests