I can't find in the manual if it tells you how to add an interface for a behavior.
I did the following in the behavior instance.js:
const map = new WeakMap;
self.IToggleBehaviorInstance = class IToggleBehaviorInstance extends IBehaviorInstance {
constructor() {
super();
map.set(this, IBehaviorInstance._GetInitInst().GetSdkInstance())
}
getState(i) {
return map.get(this)._GetState(i);
}
setState(i, v) {
C3X.RequireFiniteNumber(i);
C3X.RequireFiniteNumber(v);
return map.get(this)._SetState(i,v);
}
};
Later in an event sheet, I have the following:
const inst = runtime.objects.Sprite.getFirstInstance();
const t = runtime.objects.Text.getFirstInstance();
const toggle = inst.behavior.Toggle;
toggle.setState(0,3);
t.text = toggle.getState(0);
But I get an error saying: TypeError: Cannot read properties of undefined (reading 'Toggle')
I've looked at the official behaviors, and I don't see what I am doing wrong (unless you just aren't allowed to define interfaces?)