Lunalua Help

Need help with any SMBX game-related issues? Ask your questions here.

Moderator: Userbase Moderators

Levelmaker_123
Spiny
Spiny
Posts: 25
Joined: Fri Dec 08, 2023 1:46 pm
Pronouns: he
Contact:

Lunalua Help

Postby Levelmaker_123 » Mon Nov 18, 2024 5:06 pm

Explanation:
After you kill the boss an event gets activated and after that event activates it diactivates an event which should come after of you didn't kill the boss.
Here's a simpler version: A boss is in phase 2 of you kill it it activates the boss's (death) event. But of you don't kill it then the boss enteres phase 1 (With an event delay) So I need a way to "deactivate" an event after another event was "activated"
I assume this could be done in lunalua somhow. And I did read the documentation tho I probably skipped a part or something.

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9876
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Lunalua Help

Postby Emral » Mon Nov 18, 2024 5:37 pm

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.

Levelmaker_123
Spiny
Spiny
Posts: 25
Joined: Fri Dec 08, 2023 1:46 pm
Pronouns: he
Contact:

Re: Lunalua Help

Postby Levelmaker_123 » Tue Nov 19, 2024 10:14 am

Thanks!


Return to “Help and Support”

Who is online

Users browsing this forum: Semrush [Bot] and 1 guest

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari