Page 1 of 1

Escape Sequence Levels?

Posted: Tue Nov 05, 2019 7:35 am
by Sky-Streamer
Hello! I'm currently wanting to create some sort of timer for an escape sequence after an event in a level, similar to the escape sequences in Wario Land 4 and Pizza Tower. Are there any episodes or levels with this mechanic, and does anyone have any advice on how to make a timer and escape sequence in a level? Thank you!

Re: Escape Sequence Levels?

Posted: Thu Nov 07, 2019 4:03 pm
by Cedur
Check out on how to implement a timer in SMBX2 (leveltimer.lua is included by default). Look on Youtube for general Lua advice or maybe wait for an SMBX2 dev to post here

Re: Escape Sequence Levels?

Posted: Fri Nov 08, 2019 1:32 pm
by Enjl
Making a timed event is as simple as triggering an event in the editor (i.e. making some sort of action like hitting a block or killing an enemy trigger an event), and having that event trigger another event after a certain delay (the bottommost function, in the SMBX2 editor).

For a more traditional timer (in SMBX2PAL), go to Scripts -> level local (luna.lua) in the SMBX2 editor, and type in the following code:
local timer = require("timer")
timer.activate(500)

This will activate a timer like in the traditional marios, set to 500 seconds. You can change the number of seconds by changing the number in parentheses. You can also trigger this timer from a SMBX event. Say, for example, if you have an event called "ActivateTimer" in the editor. This event doesn't need to do anything in the editor. But in the code we can do something when it gets activated. The code for that would look like this:

local timer = require("timer")
function onEvent(eventName)
if eventName == "ActivateTimer" then
timer.activate(500)
end
end

Same as before, but this time we only activate it once the event is triggered. onEvent basically is for pieces of code that should run when any SMBX event is triggered. Using the if statement we can narrow it down by the name of the event that's been triggered.

For more fancy secondary effects, you will have to experiment with events or lunalua.
You can find a guide on Layers and Events in this thread: viewtopic.php?f=35&t=10507
And the (older) documentation for lunalua here: https://wohlsoft.ru/pgewiki/Category:LunaLua_API
For the lunalua documentation, I recommend starting at the "How To" section if you haven't programmed much in the past. Also, stuff like timer.lua isn't documented there as we're moving the documentation elsewhere, but the new one isn't quite ready yet.
I've documented the new features on this handbook for the time being. Here's a link directly to the section about the timer: https://docs.google.com/document/d/1uOd ... 1h3s6vmjm7