Davidobot / love.js

LÖVE ported to the web using Emscripten, updated to the latest Emscripten and LÖVE (v11.5)
MIT License
605 stars 27 forks source link

is there a global variable for the love.js worker? #84

Open lilmike opened 9 months ago

lilmike commented 9 months ago

Hiya,

I'm trying to do something rather complicated, where I send a message from the love.worker.js to the main thread of the browser, which then causes an event listener to run some javascript code on the main thread. However, I'm having trouble identifying if there is a global variable for the worker that runs the lua code. I essentially just need to add an event listener, but that require me to know the variable containing the worker... and this code is complicated as all get out haha. Can you perhaps point me to the variable containing the worker?

Thanks,

-Michael.

alexjgriffith commented 5 months ago

love.worker.js enables love.thread in love.js. It is not designed to be accessed directly from within the love environment. If you want to create a worker and pass commands to it in the love environment you would do so the same as you would for a native game (so long as you are using the release target, not the compat target). There is a simple example on the wiki love.thread. Like the main thread, this thread would have no access to the javascript environment.

If you want to make a callback into the javascript environment, love.js-api-player provides an async interop. There is an example setup in #89.