MCPcopy Create free account
hub / github.com/aiscript-dev/aiscript / assign

Method assign

src/interpreter/scope.ts:135–156  ·  view source on GitHub ↗
(name: string, val: Value)

Source from the content-addressed store, hash-verified

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}

Callers 1

setMethod · 0.80

Calls 3

logMethod · 0.95
onUpdatedMethod · 0.95
getMethod · 0.65

Tested by

no test coverage detected