mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-01-07 07:06:05 +01:00
better handling of array / object vars
This commit is contained in:
parent
0290916035
commit
afd32d1f4d
@ -11,7 +11,15 @@ function getLocalVariable(name, args = {}) {
|
|||||||
if (args.index !== undefined) {
|
if (args.index !== undefined) {
|
||||||
try {
|
try {
|
||||||
localVariable = JSON.parse(localVariable);
|
localVariable = JSON.parse(localVariable);
|
||||||
localVariable = localVariable[Number(args.index)];
|
const numIndex = Number(args.index);
|
||||||
|
if (Number.isNaN(numIndex)) {
|
||||||
|
localVariable = localVariable[args.index];
|
||||||
|
} else {
|
||||||
|
localVariable = localVariable[Number(args.index)];
|
||||||
|
}
|
||||||
|
if (typeof localVariable == 'object') {
|
||||||
|
localVariable = JSON.stringify(localVariable);
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// that didn't work
|
// that didn't work
|
||||||
}
|
}
|
||||||
@ -35,7 +43,15 @@ function getGlobalVariable(name, args = {}) {
|
|||||||
if (args.index !== undefined) {
|
if (args.index !== undefined) {
|
||||||
try {
|
try {
|
||||||
globalVariable = JSON.parse(globalVariable);
|
globalVariable = JSON.parse(globalVariable);
|
||||||
globalVariable = globalVariable[Number(args.index)];
|
const numIndex = Number(args.index);
|
||||||
|
if (Number.isNaN(numIndex)) {
|
||||||
|
globalVariable = globalVariable[args.index];
|
||||||
|
} else {
|
||||||
|
globalVariable = globalVariable[Number(args.index)];
|
||||||
|
}
|
||||||
|
if (typeof globalVariable == 'object') {
|
||||||
|
globalVariable = JSON.stringify(globalVariable);
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// that didn't work
|
// that didn't work
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user