mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
/addvar on array to push
This commit is contained in:
@ -109,6 +109,14 @@ function setGlobalVariable(name, value, args = {}) {
|
|||||||
|
|
||||||
function addLocalVariable(name, value) {
|
function addLocalVariable(name, value) {
|
||||||
const currentValue = getLocalVariable(name) || 0;
|
const currentValue = getLocalVariable(name) || 0;
|
||||||
|
try {
|
||||||
|
const parsedValue = JSON.parse(currentValue);
|
||||||
|
if (typeof parsedValue == 'object' && parsedValue instanceof Array) {
|
||||||
|
parsedValue.push(value);
|
||||||
|
setGlobalVariable(name, JSON.stringify(parsedValue));
|
||||||
|
return parsedValue;
|
||||||
|
}
|
||||||
|
} catch {}
|
||||||
const increment = Number(value);
|
const increment = Number(value);
|
||||||
|
|
||||||
if (isNaN(increment) || isNaN(Number(currentValue))) {
|
if (isNaN(increment) || isNaN(Number(currentValue))) {
|
||||||
@ -129,6 +137,14 @@ function addLocalVariable(name, value) {
|
|||||||
|
|
||||||
function addGlobalVariable(name, value) {
|
function addGlobalVariable(name, value) {
|
||||||
const currentValue = getGlobalVariable(name) || 0;
|
const currentValue = getGlobalVariable(name) || 0;
|
||||||
|
try {
|
||||||
|
const parsedValue = JSON.parse(currentValue);
|
||||||
|
if (typeof parsedValue == 'object' && parsedValue instanceof Array) {
|
||||||
|
parsedValue.push(value);
|
||||||
|
setGlobalVariable(name, JSON.stringify(parsedValue));
|
||||||
|
return parsedValue;
|
||||||
|
}
|
||||||
|
} catch {}
|
||||||
const increment = Number(value);
|
const increment = Number(value);
|
||||||
|
|
||||||
if (isNaN(increment) || isNaN(Number(currentValue))) {
|
if (isNaN(increment) || isNaN(Number(currentValue))) {
|
||||||
|
Reference in New Issue
Block a user