Merge pull request #4305 from SillyTavern/feat/allow-empty-setvar

Allow empty values in {{setvar/setglobalvar}}
This commit is contained in:
Cohee
2025-07-25 22:04:56 +03:00
committed by GitHub
parent 29702a3f1b
commit 6224e20cbe
+2 -2
View File
@@ -238,7 +238,7 @@ export function resolveVariable(name, scope = null) {
export function getVariableMacros() {
return [
// Replace {{setvar::name::value}} with empty string and set the variable name to value
{ regex: /{{setvar::([^:]+)::([^}]+)}}/gi, replace: (_, name, value) => { setLocalVariable(name.trim(), value); return ''; } },
{ regex: /{{setvar::([^:]+)::([^}]*)}}/gi, replace: (_, name, value) => { setLocalVariable(name.trim(), value); return ''; } },
// Replace {{addvar::name::value}} with empty string and add value to the variable value
{ regex: /{{addvar::([^:]+)::([^}]+)}}/gi, replace: (_, name, value) => { addLocalVariable(name.trim(), value); return ''; } },
// Replace {{incvar::name}} with empty string and increment the variable name by 1
@@ -248,7 +248,7 @@ export function getVariableMacros() {
// Replace {{getvar::name}} with the value of the variable name
{ regex: /{{getvar::([^}]+)}}/gi, replace: (_, name) => getLocalVariable(name.trim()) },
// Replace {{setglobalvar::name::value}} with empty string and set the global variable name to value
{ regex: /{{setglobalvar::([^:]+)::([^}]+)}}/gi, replace: (_, name, value) => { setGlobalVariable(name.trim(), value); return ''; } },
{ regex: /{{setglobalvar::([^:]+)::([^}]*)}}/gi, replace: (_, name, value) => { setGlobalVariable(name.trim(), value); return ''; } },
// Replace {{addglobalvar::name::value}} with empty string and add value to the global variable value
{ regex: /{{addglobalvar::([^:]+)::([^}]+)}}/gi, replace: (_, name, value) => { addGlobalVariable(name.trim(), value); return ''; } },
// Replace {{incglobalvar::name}} with empty string and increment the global variable name by 1