diff --git a/src/BasicBehaveEngine/BasicBehaveEngine.ts b/src/BasicBehaveEngine/BasicBehaveEngine.ts index ddccd5f..3689b53 100644 --- a/src/BasicBehaveEngine/BasicBehaveEngine.ts +++ b/src/BasicBehaveEngine/BasicBehaveEngine.ts @@ -221,6 +221,17 @@ export class BasicBehaveEngine implements IBehaveEngine { events: this.events, }; + this.variables.forEach(variable => { + if (variable.value === undefined) { + // TODO get the default value from the type + variable.value = 0; + } + // sanitize, these need to be arrays + if (!Array.isArray(variable.value)) { + variable.value = [variable.value]; + } + }); + let index = 0; this.nodes.forEach(node => { const behaviourNodeProps: IBehaviourNodeProps = { diff --git a/src/BasicBehaveEngine/nodes/variable/VariableGet.ts b/src/BasicBehaveEngine/nodes/variable/VariableGet.ts index f0d71dc..9f1c901 100644 --- a/src/BasicBehaveEngine/nodes/variable/VariableGet.ts +++ b/src/BasicBehaveEngine/nodes/variable/VariableGet.ts @@ -20,7 +20,12 @@ export class VariableGet extends BehaveEngineNode { this.graphEngine.processNodeStarted(this); const result: Record = {}; - result["value"] = this.variables[this._variable]; + const res = this.variables[this._variable]; + // TODO It's unclear when the value needs to be a glTF value (always an array) + // or when it needs to be the actual value. Since the result of this node is always parsed + // with parseType, it currently needs to be an array. + if (!Array.isArray(res.value)) res.value = [res.value]; + result["value"] = res; return result; } } diff --git a/src/BasicBehaveEngine/nodes/variable/VariableSet.ts b/src/BasicBehaveEngine/nodes/variable/VariableSet.ts index bf15b27..98c87f7 100644 --- a/src/BasicBehaveEngine/nodes/variable/VariableSet.ts +++ b/src/BasicBehaveEngine/nodes/variable/VariableSet.ts @@ -22,7 +22,7 @@ export class VariableSet extends BehaveEngineNode { const vals = this.evaluateAllValues(["value"]); this.graphEngine.processNodeStarted(this); - this.variables[this._variable].value = vals[variable.id]; + this.variables[this._variable].value = vals["value"]; super.processNode(flowSocket); }