How do I use function from another js file into the scriptsInEvents.js(the scripts in the eventsheet

0 favourites
  • 3 posts
From the Asset Store
Convert multiple Excel files into JSON files and import them into construct3.
  • so I'm literally crying right now as the function I created is not working saying that it is not defined I thought that it is because the scope of the function can't reach the scriptsInEvents.js so I use import following this construct.net/en/tutorials/upgrading-projects-classic-2652

    and it's still now working idk what to do T_T

    the code in event sheet is like this

    var AllEnemies = runtime.objects.EnemyDetector.getAllInstances();

    var EnemyUID = [];

    addEnemyUID(AllEnemies, EnemyUID);

    console.log(EnemyUID);

    var temp = AllEnemies[AllEnemies.length-1];

    console.log(temp.uid);

    and the function on the utilities.js which is addEnemyUID()

    export function addEnemyUID(AllEnemies, EnemyUID){

    var instance = AllEnemies[AllEnemies.length-1];

    EnemyUID.push({id: instance.uid});

    }

    importsForEvents.js

    import * as Utils from "./utilities.js";

    I'm new to construct and javascript so I might have some error in the way I code or iDK please educate me T_T

    Tagged:

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It's quite simple, your import statement:

    	import * as Utils from "./utilities.js";
    

    Notice that you import the functions "as Utils".

    	addEnemyUID(AllEnemies, EnemyUID); // This is not defined
    	Utils.addEnemyUID(AllEnemies, EnemyUID); // But this is
    

    In other words, all the functions of Utils will be available under Utils.

  • It's quite simple, your import statement:

    > 	import * as Utils from "./utilities.js";
    

    Notice that you import the functions "as Utils".

    > 	addEnemyUID(AllEnemies, EnemyUID); // This is not defined
    	Utils.addEnemyUID(AllEnemies, EnemyUID); // But this is
    

    In other words, all the functions of Utils will be available under Utils.

    Ohhhhhh THANKYOU!!!

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