rhg1968's Forum Posts

  • Interesting side note on Import Maps ASHLEY.

    It is working now as expected on one machine. If I run the same project on 2 other PCs I get 404 errors trying to load.

    I noticed that the <script type="importmap" /> is there everything works correctly.

    On the other two machines that script tag is missing on preview and the json importmap is not included so then it can't resolve the module names.

    So I am not sure why it's included in one preview on one machine but not on my other machines.

    I would definitely appreciate any thoughts you have.

    Thank you

  • Thank you, for some reason I thought it was relative from the file that was importing a module. That makes things a lot easier :)

  • I guess my question revolves around files being in different sub-folders referring to a common import. The relative path to that shared file would be different from each file in a different sub-folder. So wouldn't that make it impossible for the same import to be utilized ?

  • I wanted to utilize a import map so that I only needed to change things in one place if the location of files in project needed to be changed. However, I ran into an issue that makes me think this will not work well with a Construct 3 project.

    The problem is that the simplest way to make the import path work in all cases is to base it off the the root of the web app. A issue arises when you export the project lets say for windows. So here is what a possible import map file looks like and a directory structure I am using.

    { "imports" : { "ecs_manager": "/ECS/ECSManager.js", "player": "/ECS/Player.js", "enemy": "/ECS/Enemy.js", "text": "/ECS/Text.js", "move_system": "/ECS/MoveSystem.js", "collision_system": "/ECS/CollisionSystem.js", "component": "/ECS/Component.js", "move_component": "/ECS/MoveComponent.js", "coll_polygon_component": "/ECS/CollPolygonComponent.js", "entity": "/ECS/Entity.js", "utilities": "/Utilities/Utilities.js", "vector": "/Utilities/Vector.js", "enemy_component": "/ECS/EnemyComponent.js", "system": "/ECS/System.js" } }

    In preview mode the /ECS directory is off of the root so I can use the key in an import statement in main.js and in a file that's in ECS folder that reference the same import because it's based off the root.

    When I export for windows there are additional directories before the ECS now so the path from root is different.

    This makes you revert back to relative paths, but now you can't use the same import map key because the path to the file is different from different directories.

    Just wondering if anyone else has a solution to this or I may just not use import maps at all.

    Thanks

    Tagged:

  • In your subclass it doesn't show that you are exporting the class.

  • Tom

    That did it, Thank you !!!

  • Tom

    I just tried again and I am still getting the error

  • I am getting ready to upload a new version of my plugin and I get an error message that archive can't contain .svg files anymore. That is icon file for the Plugin. If I download the SDK templates they have an svg file and the documentation indicates that the icon.svg file is what it is supposed to be. Just wanted to see if something has changed that I am not aware of.

  • I am on version 407.2

    I created a simple project and imported a simple class without issue.

    I was testing import maps and it throws an error that it can't resolve the import name and it needs to be relative or direct path with a . or /

    I did make the import map json of the type import map.

    This works correctly

    import {Item} from "/Items/Item.js";
    // Import any other script files here, e.g.:
    // import * as myModule from "./mymodule.js";
    
    runOnStartup(async runtime =>
    {
    	// Code to run on the loading screen.
    	// Note layouts, objects etc. are not yet available.
    	
    	runtime.addEventListener("beforeprojectstart", () => OnBeforeProjectStart(runtime));
    });
    
    async function OnBeforeProjectStart(runtime)
    {
    	// Code to run just before 'On start of layout' on
    	// the first layout. Loading has finished and initial
    	// instances are created and available to use here.
    	
    	const test = new Item(123);
    	
    	runtime.addEventListener("tick", () => Tick(runtime));
    }
    
    function Tick(runtime)
    {
    	// Code to run every tick
    }
    

    I then created a json file and set it's type to import map

    Changed my main.js file like so

    import {Item} from "myItem";
    // Import any other script files here, e.g.:
    // import * as myModule from "./mymodule.js";
    
    runOnStartup(async runtime =>
    {
    	// Code to run on the loading screen.
    	// Note layouts, objects etc. are not yet available.
    	
    	runtime.addEventListener("beforeprojectstart", () => OnBeforeProjectStart(runtime));
    });
    
    async function OnBeforeProjectStart(runtime)
    {
    	// Code to run just before 'On start of layout' on
    	// the first layout. Loading has finished and initial
    	// instances are created and available to use here.
    	
    	const test = new Item(123);
    	
    	runtime.addEventListener("tick", () => Tick(runtime));
    }
    
    function Tick(runtime)
    {
    	// Code to run every tick
    }
    

    I then get the following error

    [C3 preview] Browser opened wrong size popup: wanted 854 x 480, got 854 x 479; resizing to compensate
    local.html:1 Uncaught TypeError: Failed to resolve module specifier "myItem". Relative references must start with either "/", "./", or "../".Understand this error
    domSide.js:37 Error loading project main script: Error: main script did not run to completion
     at RuntimeInterface._InitDOM (domSide.js:37:143)
     at async RuntimeInterface._Init (domSide.js:29:261)
    _InitDOM @ domSide.js:37Understand this error
    runtime.js:26 
  • I have an addon in the store that does exactly what has been mentioned.

    construct.net/en/game-assets/addons/publish-subscribe-events-2497

  • The only thing I noticed was that you are storing your calculated result in a string and then the return type of the function is a number, which may convert it a 0.

  • I agree this feature would be game changing. GDevelop has this ability and it really is nice to be able to create behaviors in the editor using events or JavaScript snippets.

  • Thank you for getting back to me. You were right, as I looked at what my plugin was actually doing I really didn't need to call those event sheet functions. I was able to make it work correctly without those calls and now my plugin is all set for v2.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I am porting a global plugin I made awhile ago over to v2.

    In my original plugin the calls to GetCurrentEventStackFrame and GetCurrentEvent worked fine.

    Once I upgraded to V2 I get this.runtime.GetCurrentEventStackFrame is not a function

    Any guidance would be appreciated

    Here is the original condition:

    "use strict";
    
    {
    	self.C3.Plugins.RGBZ_PubSub.Cnds =
    	{
    		SubscribeToEvent(name)
    		{
    			console.info(`Subscribe called ${name}`);
    
    			const current_frame = this._runtime.GetCurrentEventStackFrame();
    			const current_event = this._runtime.GetCurrentEvent();
    	
    			const eventId = current_event._sid.toString() + '-' + current_frame._cndIndex.toString();
    
    			if (this.EventPublished && this.EventPublished.Name==name.toLowerCase() 
    					&& this.EventPublished.HandledBy.find(x=>x==eventId)==null) {
    				this.EventPublished.HandledBy.push(eventId);
    
    				return true;
    			}
    			else {
    				return false;
    			}
    		}
    	};
    }

    Here is the new V2 version

    "use strict";
    
    const C3 = globalThis.C3;
    
    C3.Plugins.RGBZ_PubSub.Cnds =
    {
    	SubscribeToEvent(name)
    	{
    		console.info(`Subscribe called ${name}`);
    
    		const current_frame = this.runtime.GetCurrentEventStackFrame();
    		const current_event = this.runtime.GetCurrentEvent();
    
    		const eventId = current_event._sid.toString() + '-' + current_frame._cndIndex.toString();
    
    		if (this.EventPublished && this.EventPublished.Name==name.toLowerCase() 
    				&& this.EventPublished.HandledBy.find(x=>x==eventId)==null) {
    			this.EventPublished.HandledBy.push(eventId);
    
    			return true;
    		}
    		else {
    			return false;
    		}
    	}
    };
    
  • Your script block is at the same level as the on start layout. So it's not part of that event. It gets called every ticket of the game.

    You need to either add it directly to on start layout or to a new sub event of the on start for it to only run once/

    If you want to call it from the event sheet as a function you should move it to a separate js file and import it into the events js file so it's available to call in the event sheet