Sami424's Recent Forum Activity

  • You need to export the class and

    > runtime.objects.plr.setInstanceClass(plr.plr);
    

    the first plr is the module, the second plr is the class.

    Hello, ok thank you.

    So basically, i noticed why it was working for me before.

    If i set instance class of a instance in main, you both are right i have to export the subclass and then use plr.plr

    However, i noticed, if i add the runOnStartUp in my subclass file, i dont have to export the class at all, and it works aswell.

    Look at the Player class here:

    class PlayerInstance extends globalThis.InstanceType.Player
    {
    
    constructor()
    {
    super();
    console.log("Created!");
    }
    
    }
    
    runOnStartup(async runtime =>
    {
    	// Code to run on the loading screen.
    	// Note layouts, objects etc. are not yet available.
    	
    	runtime.objects.Player.setInstanceClass(PlayerInstance);
    	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.
    	
    	runtime.addEventListener("tick", () => Tick(runtime));
    }
    
    function Tick(runtime)
    {
    	// Code to run every tick
    }
    
    

    Then i just import the class in main, without using export at all.

    HOWEVER, if i setInstanceClass in main, i will have to do PlayerInstance.PlayerInstance like you mentioned, and i have to export the subclass.

    Thanks for clearing this out guys, i was confused after a few hours of work yesterday.

    Have a great weekend!

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

    Hey, yeah i tried that, usually dont have to export subclasses, i might be wrong tho.

    I tried adding export, sadly still same error 😭.

  • Alright thx, feature request it is. The workaround is ok, but I always set out to do a game and make it "javascript only" just to end up back in the event sheet for random reasons. Either be it workarounds, missing APIs (or intentionally left out) or simply convenience with some things. Not a bad thing per se but not exactly what I plan, haha.

    I feel you, however after awhile you will notice that some stuff is just easier to do in the event sheet, code is still js even if you use the event sheet, i usually say if someone has done it, why redo it 😉 that said i had the same issue with some stuff like pin etc, where i had to create it myself, but then i said screw it and just used the event sheet, works fine for simple things like on start of layout etc.

  • Ok so my subclasses was working great, now i am getting error:

    runtime.js:1 [C3 runtime] Error in runOnStartup function: TypeError: expected function at C3.RequireFunction (typeChecks.js:1:2563) at self.ISpriteObjectType.setInstanceClass (IObjectClass.js:1:1269) at main.js:9:22 at C3.Runtime._RunOnStartupFunction (runtime.js:1:12581) at C3.Runtime.Init (runtime.js:1:12030) at async Q._InitDOM (domSide.js:16:12442) at async Q._Init (domSide.js:16:7621)

    But this was working great before, i tried with a empty project, and the same happened?

    Here is main.js:

    import * as plr from "./plr.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.objects.plr.setInstanceClass(plr);
    	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.
    	
    	runtime.addEventListener("tick", () => Tick(runtime));
    }
    
    function Tick(runtime)
    {
    	// Code to run every tick
    }
    

    Here is my subclass:

    class plr extends globalThis.InstanceType.plr
    {
    
    constructor(){
    super();
    console.log("toatewg");
    }
    }

    I have now tried multiple fresh projects, i am unable to subclass, i have no idea why.

    [b

    ] P.S: Whoever thought "undo" should apply to all my script files in a project and not the CURRENT script file im working on, you and me we have a problem !

  • Why dont you want to just import the files in c3 by right clicking the sounds folder ? Just curious

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You want to upload a file from the code ? Am i correct ?

  • If i am correct, your trying to make it like a candy crush feature almost, that if 3 same color blocks are on eachother they will get removed ?

  • The code in your initial post appears to be correct. Maybe you didn't set the right script purpose properties. The easiest way to get help is to share a project file, so others can see exactly what you've done - otherwise all we can do is guess.

    Basically the code above is all i did to test the import/export. I solved it as the problem was on my end, i forgot to export the class properly. Thanks for your reply

  • See the guide in the manual on using an external editor.

    Thanks for your answer, i read it and i kind off did that but my intellisense etc is not catching up the c3 classes etc. I might done something wrong, i will try again. Thanks

  • You can use APIs online, such as firebase etc.

    Or make your own using php and storing data to database and use Ajax calls to save to it from c3

  • I have been looking around, i found a very old plugin for VS code that doesnt seem to work. Any way for me to work in vs code for my construct 3 scripts? I work with VS Code so this would make stuff much easier.

  • Alright so i solved it by doing

    // I import the class named myClass from my js file, the class has an export tag. 
    import { myClass } from "./myclass.js" ;
    
    // I instantiate the class
    let customClass = new myClass();
    // I can now use the functions declared inside myClass
    customClass.runMyFunction();
    
    

    This is working, i dont know if i am doing it correct, but this way its working. I am getting more familiar with the import/export in construct.

Sami424's avatar

Sami424

Member since 9 Jul, 2018

Twitter
Sami424 has 5 followers

Trophy Case

  • 6-Year Club
  • Entrepreneur Sold something in the asset store
  • Forum Contributor Made 100 posts in the forums
  • Regular Visitor Visited Construct.net 7 days in a row
  • RTFM Read the fabulous manual
  • Email Verified

Progress

11/44
How to earn trophies