From 26c2e43e5d784cfe344b70e91b5c2afda112ba70 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sun, 7 May 2023 20:44:37 +0200 Subject: Fix else. --- rules.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/rules.js b/rules.js index 0aac4cc..d293e17 100644 --- a/rules.js +++ b/rules.js @@ -2068,7 +2068,22 @@ function vm_if() { } function vm_else() { - vm_goto(vm_endif, vm_if, 1, 1) + vm_jump(vm_endif, vm_if, 1, 1) +} + +function vm_jump(op, nop, dir, step) { + let balance = 1 + while (balance > 0) { + game.vm.ip += dir + if (vm_inst(0) === op) + --balance + if (vm_inst(0) === nop) + ++balance + if (game.vm.ip < 0 || game.vm.ip > CODE[game.vm.fp].length) + throw "ERROR" + } + game.vm.ip += step + vm_exec() } function vm_endif() { -- cgit v1.2.3