Accessing a script from an action.

0 favourites
  • 3 posts
From the Asset Store
11 loops of RPG, chiptune/8-bit music. Suitable for any pixel art game.
  • If I have a script `c3runtime/lib.js` which has stuff I want to use in my action(s) - how I inject that functionality into my action functions?

    Maybe related: how do I access plugin properties from an action function?

  • The typical way is to assign the properties to instance properties on construction in c3runtime/instance.js and then refer to those properties in actions, etc.

     C3.Plugins.Mikal_Example.Instance = class ExampleInstance extends C3.SDKWorldInstanceBase
     {
     constructor(inst, properties)
     {
     if (properties)
     {
     this.scale = properties[0];
    

    In action refer to the class property:

    	const newScale = this.scale * 2;
    

    for lib.js, since addons don't work with modules (e.g. import), I create a global pointer to the library/class and use that in actions.

    e.g. in lib.js I have

    if (!globalThis.myC3Lib) globalThis.myC3Lib = myLib;
    

    then in actions I use it by:

    const myLib = globalThis.myC3Lib;
    myLib.doFunction(this.scale);
    
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • That's very helpful...thanks.

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