From be7c12ff39a891f8d13d6071c4f9787d0785b9a5 Mon Sep 17 00:00:00 2001 From: aliciusschroeder Date: Tue, 3 Feb 2026 19:04:30 +0100 Subject: [PATCH] Fix TypeError crash in --thorough mode on V1-3 Z-machine games save/restore opcodes use branch semantics in V1-3 but store in V4+. The step() handler unconditionally called set_variable(store_var, ...) which crashed with None when store_var wasn't set for V3 games. --- zwalker/zmachine.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/zwalker/zmachine.py b/zwalker/zmachine.py index 4948f0e..93b7d60 100644 --- a/zwalker/zmachine.py +++ b/zwalker/zmachine.py @@ -2011,11 +2011,17 @@ def handle_char(input_text: str): # Extended elif name == "save": # For automated walking, always succeed - self.set_variable(store_var, 1) + if store_var is not None: + self.set_variable(store_var, 1) # V4+ + elif branch is not None: + self._do_branch(True, branch) # V1-3: branch on success elif name == "restore": # For automated walking, always fail (no saved game to restore) - self.set_variable(store_var, 0) + if store_var is not None: + self.set_variable(store_var, 0) # V4+ + elif branch is not None: + self._do_branch(False, branch) # V1-3: don't branch (failure) elif name == "save_undo": self.set_variable(store_var, 1) # Success (but we don't actually save)