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?
Develop games in your browser. Powerful, performant & highly capable.
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);
That's very helpful...thanks.