While you can't tell an event to stop, you can be sure to not trigger the next event in a chain until a condition is met by using LunaLua.
I imagine your phase 1 loop is something like this:
Event1 triggers Event2, triggers Event3, triggers Event4, triggers Event1 and the cycle continues.
At any point where you want to break the cycle, do not use the event trigger field in the editor, but route the event delay through lua.
I'll post a short code snippit and explain it.
Code: Select all
local phase1Active = true
local function triggerEventWithDelay(nextEvent, delaySeconds)
Routine.wait(delaySeconds)
if phase1Active then
triggerEvent(nextEvent)
end
end
function onEvent(eventName)
if eventName == "Event1" then
Routine.run(triggerEventWithDelay, "Event2", 2)
end
if eventName == "Event2" then
Routine.run(triggerEventWithDelay, "Event3", 1)
end
if eventName == "Event3" then
Routine.run(triggerEventWithDelay, "Event4", 2)
end
if eventName == "Event4" then
Routine.run(triggerEventWithDelay, "Event1", 1)
end
if eventName == "Phase1Over" then
phase1Active = false
end
end
The above code has two important functions. Let's start with the bottom one, "onEvent". This is a function that runs every time a SMBX event executes. The eventName is the name of the event that is running at this moment. By checking which event runs we can execute different code. In this case this is either running a routine (more on that in a bit), or telling the code that phase 1 is over.
A routine is a function that runs over the course of a longer period of time. When calling Routine.run, the first thing in parentheses is the function you want to run, and everything after are the function arguments. Configuration values for the function's logic. In our case for the function triggerEventWithDelay, this is the event we want to trigger next, and how many seconds later it should happen.
The secret sauce is what happens before we trigger the event with triggerEvent. We check if phase1Active is still true. Once the Phase1Over event runs, this will no longer be the case, thanks to our onEvent function. So as soon as that event runs, the Phase 1 loop of Event1, Event2, Event3 and Event4 will be permanently interrupted.
Important: This setup only works if the events do not trigger each other in the SMBX editor.
How to customize the code:
- change the event names in quotation marks
- change the delay seconds
- add and remove if statements checking eventName against different event names to lengthen or shorten the event loop
- If you have more phases to be concerned about, add a new variable "local phase2Active" and make a triggerEventWithDelayPhase2 that uses that one instead, and build a new event loop. Remember that everything goes in the same onEvent. You cannot have a second onEvent function, else things will break.
Hope this helps! Let me know if you have any questions.