fix: resolve state_unsafe_mutation in getChatVar() (#707)

# PR Checklist
- [ ] Have you checked if it works normally in all models? *Ignore this
if it doesn't use models.*
- [ ] Have you checked if it works normally in all web, local, and node
hosted versions? If it doesn't, have you blocked it in those versions?
- [ ] Have you added type definitions?

# Description
While investigating an issue where `{{getvar::A}}` didn't work properly
in background embedding, I encountered a `state_unsafe_mutation` error.
It appears that modifying the null check operator on the relevant line
can resolve this issue. Thank for your time.
This commit is contained in:
kwaroran
2025-01-11 01:44:01 +09:00
committed by GitHub
2 changed files with 2 additions and 1 deletions

View File

@@ -2172,7 +2172,7 @@ export function getChatVar(key:string){
return 'null'
}
const chat = char.chats[char.chatPage]
chat.scriptstate = chat.scriptstate ?? {}
chat.scriptstate ??= {}
const state = (chat.scriptstate['$' + key])
if(state === undefined || state === null){
const defaultVariables = parseKeyValue(char.defaultVariables).concat(parseKeyValue(DBState.db.templateDefaultVariables))

View File

@@ -277,6 +277,7 @@ export async function processScriptFull(char:character|groupChat|simpleCharacter
for(const m of meta){
if(m.startsWith('order ')){
order = parseInt(m.substring(6))
orderChanged = true
}
else{
actions.push(m)