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!
Pauses (Waits, sleeps, etc.), is it Possible?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Pauses (Waits, sleeps, etc.), is it Possible?
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.)
Re: Pauses (Waits, sleeps, etc.), is it Possible?
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.
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.
Re: Pauses (Waits, sleeps, etc.), is it Possible?
You haven't told us yet what it exactly is you want to do.nate890 wrote:what I wanted 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.
Re: Pauses (Waits, sleeps, etc.), is it Possible?
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;
}
Re: Pauses (Waits, sleeps, etc.), is it Possible?
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.).
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.
- 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?
You might want to know that if threads error, they 'send' a variable 'error' containing the error message.
Re: Pauses (Waits, sleeps, etc.), is it Possible?
That's good to know .bartbes wrote:You might want to know that if threads error, they 'send' a variable 'error' containing the error message.
Oops, meant to put that in, my bad.The function is called love.timer.sleep.
- 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?
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:
So if you'll be using love.timer.sleep, start with:
Code: Select all
require "love.timer"
Re: Pauses (Waits, sleeps, etc.), is it Possible?
That is hard to imagine... 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?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.
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
Who is online
Users browsing this forum: Google [Bot] and 224 guests