| 114 | */ |
| 115 | @autobind |
| 116 | public add(name: string, variable: Variable): void { |
| 117 | this.log('add', { var: name, val: variable }); |
| 118 | const states = this.layerdStates[0]!; |
| 119 | if (states.has(name)) { |
| 120 | throw new AiScriptRuntimeError( |
| 121 | `Variable '${name}' already exists in scope '${this.name}'`, |
| 122 | { scope: this.layerdStates }); |
| 123 | } |
| 124 | states.set(name, variable); |
| 125 | if (this.parent == null) this.onUpdated(name, variable.value); |
| 126 | else if (this.nsName != null) this.parent.add(this.nsName + ':' + name, variable); |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * 指定した名前の変数に値を再代入します |