Pauses (Waits, sleeps, etc.), is it Possible?

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.
nate890
Prole
Posts: 25
Joined: Tue Jan 24, 2012 10:50 pm

Pauses (Waits, sleeps, etc.), is it Possible?

Post by nate890 »

Is it possible to pause a thread in Love2D? I'm trying to loop something and the program keeps crashing because it's looping to quickly.

If it is possible, can I please see an example, please? Thanks!
scirath
Citizen
Posts: 85
Joined: Mon Feb 23, 2009 4:44 am

Re: Pauses (Waits, sleeps, etc.), is it Possible?

Post by scirath »

I think love.timer.sleep() would be what you're looking for. https://love2d.org/wiki/love.timer.sleep
(USER MIGHT BE BANNED FOR THIS POST.)
nate890
Prole
Posts: 25
Joined: Tue Jan 24, 2012 10:50 pm

Re: Pauses (Waits, sleeps, etc.), is it Possible?

Post by nate890 »

Oddly it still crashes

while (true) do
love.timer.sleep(math.huge)
end

>Results in crash

I found a new way to do what I wanted to do, but I'd still like to know how I can get it to not crash.
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: Pauses (Waits, sleeps, etc.), is it Possible?

Post by Boolsheet »

nate890 wrote:what I wanted to do
You haven't told us yet what it exactly is you want to do. ;)
It's kinda hard to help if we don't know the details (especially if your question involves simultaneous multithreading). Show us some code, tell us what you expect it to do and what it actually does.

To answer your initial question: Yes, you can pause and wait in threads. Sleep was already mentioned. Waiting is done with Thread:demand.
Shallow indentations.
nate890
Prole
Posts: 25
Joined: Tue Jan 24, 2012 10:50 pm

Re: Pauses (Waits, sleeps, etc.), is it Possible?

Post by nate890 »

The code isn't much, that's why I didn't post it, but sure;

Code: Select all

local keys={
	["w"]=function()
		while true do
			x=x+1
			love.thread.sleep(10) --Crashes, still
		end
	end;
}
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: Pauses (Waits, sleeps, etc.), is it Possible?

Post by Boolsheet »

Even if it isn't much, there's things like typos that can be spotted and pointed out like here.
The function is called love.timer.sleep.

I hope there's more code that breaks the infinite loop, because that doesn't quite make sense.

Also, we usually don't refer to the blue Lua error screen as a crash, it's just an error. If LÖVE crashes, the application would be terminated immediately (on Windows you get those "Stopped respoding"/"Error occured" dialogs. On Linux it's just a "segfault" or something in the console.).
Shallow indentations.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Pauses (Waits, sleeps, etc.), is it Possible?

Post by bartbes »

You might want to know that if threads error, they 'send' a variable 'error' containing the error message.
nate890
Prole
Posts: 25
Joined: Tue Jan 24, 2012 10:50 pm

Re: Pauses (Waits, sleeps, etc.), is it Possible?

Post by nate890 »

bartbes wrote:You might want to know that if threads error, they 'send' a variable 'error' containing the error message.
That's good to know :).
The function is called love.timer.sleep.
Oops, meant to put that in, my bad.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Pauses (Waits, sleeps, etc.), is it Possible?

Post by bartbes »

Also, since there's only one love module loaded in a new thread, you'd want to start the thread with a few requires.
So if you'll be using love.timer.sleep, start with:

Code: Select all

require "love.timer"
User avatar
miko
Party member
Posts: 410
Joined: Fri Nov 26, 2010 2:25 pm
Location: PL

Re: Pauses (Waits, sleeps, etc.), is it Possible?

Post by miko »

nate890 wrote:Is it possible to pause a thread in Love2D? I'm trying to loop something and the program keeps crashing because it's looping to quickly.
That is hard to imagine... :o: Everyone here tries to make his program to loop as quickly as possible. I think it does not crash because it's too fast, but because there is an error in your code. Can you see an error message? What does it say?
Get rid of this root cause, then it will not crash. Add some debug info - print it out to the console. There is no need to mess with pausing threads to spot the bug.
My lovely code lives at GitHub: http://github.com/miko/Love2d-samples
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 224 guests