Only convert variable if needed
| @@ -57,7 +57,6 @@ export class SlashCommandScope { | ||
| 57 | 57 | this.variables[key] = value; |
| 58 | 58 | } |
| 59 | 59 | setVariable(key, value, index = null, type = null) { |
| 60 | - value = convertValueType(value, type); | |
| 61 | 60 | if (this.existsVariableInScope(key)) { |
| 62 | 61 | if (index !== null && index !== undefined) { |
| 63 | 62 | let v = this.variables[key]; |
| @@ -65,13 +64,13 @@ export class SlashCommandScope { | ||
| 65 | 64 | v = JSON.parse(v); |
| 66 | 65 | const numIndex = Number(index); |
| 67 | 66 | if (Number.isNaN(numIndex)) { |
| 68 | 67 | v[index] = convertValueType(value, type); |
| 69 | 68 | } else { |
| 70 | 69 | v[numIndex] = convertValueType(value, type); |
| 71 | 70 | } |
| 72 | 71 | v = JSON.stringify(v); |
| 73 | 72 | } catch { |
| 74 | 73 | v[index] = convertValueType(value, type); |
| 75 | 74 | } |
| 76 | 75 | this.variables[key] = v; |
| 77 | 76 | } else { |
| @@ -80,7 +79,7 @@ export class SlashCommandScope { | ||
| 80 | 79 | return value; |
| 81 | 80 | } |
| 82 | 81 | if (this.parent) { |
| 83 | 82 | return this.parent.setVariable(key, value, index, type); |
| 84 | 83 | } |
| 85 | 84 | throw new SlashCommandScopeVariableNotFoundError(`No such variable: "${key}"`); |
| 86 | 85 | } |
| @@ -51,19 +51,18 @@ function setLocalVariable(name, value, args = {}) { | ||
| 51 | 51 | |
| 52 | 52 | if (args.index !== undefined) { |
| 53 | 53 | try { |
| 54 | - value = convertValueType(value, args.type); | |
| 55 | 54 | let localVariable = JSON.parse(chat_metadata.variables[name] ?? 'null'); |
| 56 | 55 | const numIndex = Number(args.index); |
| 57 | 56 | if (Number.isNaN(numIndex)) { |
| 58 | 57 | if (localVariable === null) { |
| 59 | 58 | localVariable = {}; |
| 60 | 59 | } |
| 61 | 60 | localVariable[args.index] = convertValueType(value, args.type); |
| 62 | 61 | } else { |
| 63 | 62 | if (localVariable === null) { |
| 64 | 63 | localVariable = []; |
| 65 | 64 | } |
| 66 | 65 | localVariable[numIndex] = convertValueType(value, args.type); |
| 67 | 66 | } |
| 68 | 67 | chat_metadata.variables[name] = JSON.stringify(localVariable); |
| 69 | 68 | } catch { |
| @@ -101,19 +100,18 @@ function getGlobalVariable(name, args = {}) { | ||
| 101 | 100 | function setGlobalVariable(name, value, args = {}) { |
| 102 | 101 | if (args.index !== undefined) { |
| 103 | 102 | try { |
| 104 | - value = convertValueType(value, args.type); | |
| 105 | 103 | let globalVariable = JSON.parse(extension_settings.variables.global[name] ?? 'null'); |
| 106 | 104 | const numIndex = Number(args.index); |
| 107 | 105 | if (Number.isNaN(numIndex)) { |
| 108 | 106 | if (globalVariable === null) { |
| 109 | 107 | globalVariable = {}; |
| 110 | 108 | } |
| 111 | 109 | globalVariable[args.index] = convertValueType(value, args.type); |
| 112 | 110 | } else { |
| 113 | 111 | if (globalVariable === null) { |
| 114 | 112 | globalVariable = []; |
| 115 | 113 | } |
| 116 | 114 | globalVariable[numIndex] = convertValueType(value, args.type); |
| 117 | 115 | } |
| 118 | 116 | extension_settings.variables.global[name] = JSON.stringify(globalVariable); |
| 119 | 117 | } catch { |