Here is main.js:
let myNumber = 5; export function getMyNumber(){ return myNumber; }
here is importsForEvents.js
import { getMyNumber } from "./main.js";
Purpose of the imports file is set to import for events.
Why is getMyNumber() still undefined when ran on start of layout in event sheet as script?
Im not sure what i am doing wrong,
Lets say i create a class :
class myClass { Let x = 5; alertUser() { alert('works'); } }
Now in main.js i need to import this class right ?
import * as myClass from ("./myClass.js");
Even if i add export to the class, this still gives me undefined class error, what am i doing wrong? I know programming i am just stuck on the import/export part.
I am trying this in the main.js file so i am not trying to run scripts from event sheet.
Develop games in your browser. Powerful, performant & highly capable.
Edit: so importing and exporting functions is working for me.
How do i import a class for example a sub class that i made ? Do i have to instantiate the class before using it like
Let myClass = new myClass():
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.
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.