Noob question: How do I add functions I can use in eventsheet javascript? (solved)

0 favourites
  • 1 posts
From the Asset Store
Customize the animation of character when item changed
  • I created a script file: "scripts" with the following:

    function CoolMath(x,y) {

    return x + y;

    }

    In my event sheet, I then have an javascript action:

    runtime.GlobalVars.SomeVar = CoolMath(1,1);

    Auto complete all brought up what I typed, so I figured it would be valid, but its not. SomeVar never gets changed. I am assuming I need to somehow import "scripts.js"?

    EDIT

    Found the problem - I didn't have the property set correctly for "importsforevents.js". It was set to none. I also added "export" keyword to my function name edited the function call to m.CoolMath to reflect the import call.

    Integration with scripts in events

    Unlike legacy "classic" mode scripts, modules have their own top-level scope. This means things like a top-level function declaration is not available in other script files.

    Instead you can add imports to the script file with the purpose Imports for events which then become available for scripts in events. See the section Using imports in Scripts in event sheets for more details.

    Another option is to write globals as explicit properties of globalThis, e.g. globalThis.myFunction = function () { ... } and call it via globalThis.myFunction(), but using modules is preferable.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)