Does worker run on window build?

0 favourites
  • 5 posts
From the Asset Store
Full game Construct 2 and Construct 3 to post on Google Play
  • Hi, I am having issues where my exported Windows build game does not run properly and does not produce any errors.

    I am not using the advanced Worker properties in Construct 3.

    However, I wrote my own script to run the worker. I tested it on the Construct 3 editor, and it work and run as intended. However, once I exported it to a Windows build without minify mode, it runs but does not respond or show any error from the script in worker.js.

    //main.js

    	console.log("main call worker.js");
    
    	const worker = new Worker('worker.js');
    	worker.postMessage({ 
    		type: 'processMoves', 
    	});
    		
    	worker.onmessage = (event) => { 
    		if (event.data.type === 'bestMove') {
    			//Do Something 
    			}
    		}
    			
    	worker.terminate();
    

    //worker.js

    	 self.addEventListener('message', async function(event) {
     if (event.data.type === 'processMoves') {
    	console.log("Worker start");
    	try {
    		// Do somthing
    		console.log("Worker end");
     	self.postMessage({ type: 'bestMove', bestMove: bestMove});
     	} catch (error) {
     console.error('Error processing moves:', error);
     }
     }
    });
    

    Expected it to print out "Worker start" and "Worker end" in the window build, however nothing happen.

    Did i miss something or worker does not work on window build ?

  • Workers should work in Windows exports. It's hard to say more from just this information - the fastest way to get help is to share a sample project demonstrating the problem.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Ashley Thanks for the support as always.

    I create a new project with simple worker.js script and still having the same issues.

    Construct 3 Editor (Expected Result)

    Window Build

    Following is my window build setting:

    c3p Project File

    https://drive.google.com/file/d/1jU7Li1XbZJWjpMQNl8vRB8g-46hcxFBr/view?usp=sharing

  • You need to put the worker script in the 'Files' folder of the Project Bar. Otherwise Construct treats it like your other scripts, which either get minified or go in a subfolder on export. To make sure a script doesn't go through that process on export, you need to have it in the folder for general files, so it's just copied as-is.

  • It is working, You such a life saver. Thanks.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)