I have been making a game in Love, and I ran into an issue that *could* have been explained here, but I couldn't find a definitive answer.
My first question is: How to add a love callback function to a thread file that works just like standard love callback? I tried many things, but none worked. (By that i mean putting something like love.draw inside my thread)
My second question: How do I stop threads? I have multiple threads, for animations (I need draw in them, look question 1), for sound, for scrolling, for player input etc. Lets say player pauses the game, and I want to stop a specific thread. (Then run it but its easier). How am I supposed to stop this thread? I couldn't find any thread:Stop function...
So.. How do I make a substitute of love callbacks in thread and how to stop a thread
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 2
- Joined: Tue Sep 13, 2016 3:20 pm
Re: So.. How do I make a substitute of love callbacks in thread and how to stop a thread
it's not possible to have love.draw in a thread for technical reasons, and if it were possible, there would be logical problems arising.YourLocalLover wrote:I have been making a game in Love, and I ran into an issue that *could* have been explained here, but I couldn't find a definitive answer.
My first question is: How to add a love callback function to a thread file that works just like standard love callback? I tried many things, but none worked. (By that i mean putting something like love.draw inside my thread)
My second question: How do I stop threads? I have multiple threads, for animations (I need draw in them, look question 1), for sound, for scrolling, for player input etc. Lets say player pauses the game, and I want to stop a specific thread. (Then run it but its easier). How am I supposed to stop this thread? I couldn't find any thread:Stop function...
your main event loops is in your main thread (see love.run) and it doesn't make sense (= will probably break stuff) if you use love.event in another thread. You will just need to write something similar to love.run that does what exactly want it to.
Re: So.. How do I make a substitute of love callbacks in thread and how to stop a thread
Specifically, you can't use the love.graphics functions in a thread, per the [wiki]love.thread[/wiki] docs, so it makes little sense to have a love.draw callback in a thread.
-
- Prole
- Posts: 2
- Joined: Tue Sep 13, 2016 3:20 pm
Re: So.. How do I make a substitute of love callbacks in thread and how to stop a thread
Oh. But how do I kill threads? It still wasn't answered yet
- zorg
- Party member
- Posts: 3465
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: So.. How do I make a substitute of love callbacks in thread and how to stop a thread
A thread is a block, basically, that has its own lua state, and only has the love.thread module loaded initially.
If the thread doesn't loop indefinitely, then it can be exited via simply returning. If it does use a loop, you can do the same with a message or whatever.
There was a :kill method before, but it was removed. I'd suggest that if you really want to control a thread from another, then send a message into it through a channel, something like "stop" or "kill", that you handle by, again, returning... or setting a variable like active to false, and letting the loop run still, but without doing any real work.
That said, from what you have said, i believe what you'd want to use are coroutines, rather than threads.
If the thread doesn't loop indefinitely, then it can be exited via simply returning. If it does use a loop, you can do the same with a message or whatever.
There was a :kill method before, but it was removed. I'd suggest that if you really want to control a thread from another, then send a message into it through a channel, something like "stop" or "kill", that you handle by, again, returning... or setting a variable like active to false, and letting the loop run still, but without doing any real work.
That said, from what you have said, i believe what you'd want to use are coroutines, rather than threads.
Me and my stuff True 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.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 4 guests