Skip to content

Commit

Permalink
fix: resolve state_unsafe_mutation in getChatVar() (#707)
Browse files Browse the repository at this point in the history
# 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.
  • Loading branch information
kwaroran authored Jan 10, 2025
2 parents 64b9b89 + 6537e09 commit 9896b68
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ts/parser.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions src/ts/process/scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9896b68

Please sign in to comment.