From 393a1013e4b3af0a85705f191200552a37377fe7 Mon Sep 17 00:00:00 2001 From: Yunus Emre Umar <77045015+emre155@users.noreply.github.com> Date: Sun, 16 Aug 2026 16:11:32 +0300 Subject: [PATCH] fix(save-editor): guard cycleMove against undefined moves in catalog Closes #1403 --- tools/save-editor/Ops.lua | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tools/save-editor/Ops.lua b/tools/save-editor/Ops.lua index 36d13c64..77ba080a 100644 --- a/tools/save-editor/Ops.lua +++ b/tools/save-editor/Ops.lua @@ -430,7 +430,7 @@ function Ops.setDv(S, mon, key, value) end function Ops.cycleMove(S, mon, slot) - if not mon then return false end + if not mon or not (S.cat and S.cat.moves and #S.cat.moves > 0) then return false end local moves = S.cat.moves local current = mon.moves and mon.moves[slot] and mon.moves[slot].id local idx = 0 @@ -439,9 +439,14 @@ function Ops.cycleMove(S, mon, slot) if id == current then idx = i break end end end - local nextId = moves[(idx % #moves) + 1] - MonOps.setMove(S.data, mon, slot, nextId) - return Ops.mark(S, ("Move %d set to %s"):format(slot, nextId)) + for step = 1, #moves do + local nextId = moves[((idx + step - 1) % #moves) + 1] + if S.data and S.data.moves and S.data.moves[nextId] then + MonOps.setMove(S.data, mon, slot, nextId) + return Ops.mark(S, ("Move %d set to %s"):format(slot, nextId)) + end + end + return false end function Ops.clearMove(S, mon, slot)