So.. How do I make a substitute of love callbacks in thread and how to stop a thread

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
YourLocalLover
Prole
Posts: 2
Joined: Tue Sep 13, 2016 3:20 pm

So.. How do I make a substitute of love callbacks in thread and how to stop a thread

Post by YourLocalLover »

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...
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: So.. How do I make a substitute of love callbacks in thread and how to stop a thread

Post by s-ol »

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...
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.

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.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
User avatar
pgimeno
Party member
Posts: 3656
Joined: Sun Oct 18, 2015 2:58 pm

Re: So.. How do I make a substitute of love callbacks in thread and how to stop a thread

Post by pgimeno »

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.
YourLocalLover
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

Post by YourLocalLover »

Oh. But how do I kill threads? It still wasn't answered yet
User avatar
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

Post by zorg »

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.
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.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 4 guests