| 133 | */ |
| 134 | @autobind |
| 135 | public assign(name: string, val: Value): void { |
| 136 | let i = 1; |
| 137 | for (const layer of this.layerdStates) { |
| 138 | if (layer.has(name)) { |
| 139 | const variable = layer.get(name)!; |
| 140 | if (!variable.isMutable) { |
| 141 | throw new AiScriptRuntimeError(`Cannot assign to an immutable variable ${name}.`); |
| 142 | } |
| 143 | |
| 144 | variable.value = val; |
| 145 | |
| 146 | this.log('assign', { var: name, val: val }); |
| 147 | if (i === this.layerdStates.length) this.onUpdated(name, val); |
| 148 | return; |
| 149 | } |
| 150 | i++; |
| 151 | } |
| 152 | |
| 153 | throw new AiScriptRuntimeError( |
| 154 | `No such variable '${name}' in scope '${this.name}'`, |
| 155 | { scope: this.layerdStates }); |
| 156 | } |
| 157 | } |