layerfix.lua - No more looping event desyncing!

Share and discuss custom LunaLua code and content packs for SMBX2.

Moderator: Userbase Moderators

Alucard648
Tweeter
Tweeter
Posts: 170
Joined: Sun Aug 16, 2015 3:45 am

layerfix.lua - No more looping event desyncing!

Postby Alucard648 » Wed Apr 09, 2025 9:00 pm

SMBX2 editor has Blocks-per-second calculator for converting blocks per second into pixels per frame for vanilla layer movement speed. The problem is that on attempt to make a crusher using looping vanilla SMBX events, with different up and down speed, just like classical layer operated crushers in SMW, and then running them for a long time (as long as actual normal level playtime) causes them to eventually desync and potentially wreck your level, something like this:
LAYERS BEFORE FIX: show
Image
This problem occurs because of floating point imprecision. With faster speeds, imprecision can build up really quickly. For some reason even setting layer speeds to integer values still cause them to go off bounds over time. Only setting layer speeds to same value worked in loops, as I have seen in many SMBX1.3 levels.
Enter layerfix.lua. This script attempts to fix this issue by grid-snapping all blocks, BGOs and certain NPCs placed on layer every time vanilla SMBX event changes layer movement speed. If the script works properly looping events should never desync over time, just like this:
LAYERS AFTER FIX: show
Image
To install the fix, just load API in your level luna.lua file and that is it. Everything, including fetching all vanilla SMBX events that move layers, is automatically done from played level file.

DOWNLOAD


deice
Volcano Lotus
Volcano Lotus
Posts: 596
Joined: Fri Jul 23, 2021 7:35 am

Re: layerfix.lua - No more looping event desyncing!

Postby deice » Thu Apr 10, 2025 3:23 am

as a heads up for the future, if you want to grab data from a level file you don't have to write your own parser.
the LoadVanillaLayerMovementEvents could be simplified in its entirety to something along the lines of:

Code: Select all

local file = FileFormats.openLevel(Level.filename())
for _, event in ipairs(file.events) do
    layermove[event.name] = event.moveLayer
end
i don't remember if this library is actually documented despite being a basegame feature, but more can be gleamed about it from here if it's not

Alucard648
Tweeter
Tweeter
Posts: 170
Joined: Sun Aug 16, 2015 3:45 am

Re: layerfix.lua - No more looping event desyncing!

Postby Alucard648 » Thu Apr 10, 2025 7:24 am

It was undocumented. At least, no such functions were found in Codehaus docs.


Return to “LunaLua”

Who is online

Users browsing this forum: No registered users and 7 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari