-- Gen 2 script ordering: sdefer and reanchormap. -- -- Both are pure ordering, which is why nothing caught them: the flags and the -- geometry a scene script writes land identically either way. What changes is -- WHEN the deferred body runs -- inside the scene script, under the map's -- fade-in, or after it as the pass's own player event. -- luajit tests/gen2_script_order_test.lua package.path = "./?.lua;./?/init.lua;" .. package.path local S = require("tests.harness").suite("gen2 script order") local check, eq = S.check, S.eq love = require("tests.love_stub") local Events = require("src.world.gen2.Events") local Vm = require("src.script.gen2.Vm") -- ------------------------------------------------------------------- sdefer -- -- RunSceneScript (engine/overworld/events.asm:388) clears RUN_DEFERRED_SCRIPT, -- runs the scene body through ScriptEvents to its `end`, and only THEN -- CallScript's whatever `sdefer` recorded. The five League walk-ins, the Hall -- of Fame induction, the Cerulean grunt and the Mt Moon rival cutscene are all -- written `sdefer / end`. local function order(scripts) local seen = {} local vm = Vm.new(scripts, {}, Events.new(), { showText = function(body, onDone) seen[#seen + 1] = body onDone() end, }) return vm, seen end do local vm, seen = order({ generation = 2, ["scene"] = { { op = "sdefer", script = "deferred" }, { op = "rawtext", text = "scene tail" }, { op = "end" }, }, ["deferred"] = { { op = "rawtext", text = "deferred body" }, { op = "end" }, }, }) vm:start("scene") eq(#seen, 2, "both bodies ran") eq(seen[1], "scene tail", "the scene body runs first, all of it") eq(seen[2], "deferred body", "and the deferred script only after its `end`") check(not vm:running(), "and the pair leave nothing running") end -- The shape the cache actually carries: `sdefer