How to save triggered events

Post here for help and support regarding LunaLua and SMBX2's libraries and features.

Moderator: Userbase Moderators

AlphaBlue1011
Spiny
Spiny
Posts: 29
Joined: Sun Feb 02, 2025 3:00 pm
Flair: never underestimate hyperfixations :3
Pronouns: she/her or they/them

How to save triggered events

Postby AlphaBlue1011 » Fri Feb 14, 2025 1:36 pm

So, I want to make it so when an event is triggered to open a door, the door stays open between revisits to that level. How would I do this?

cold soup
Swooper
Swooper
Posts: 73
Joined: Wed May 13, 2020 8:29 pm
Flair: yeah
Pronouns: they/she
Contact:

Re: How to save triggered events

Postby cold soup » Fri Feb 14, 2025 2:17 pm

there's a few steps you gotta do but it's not that complicated overall. first you'd have to add an onEvent function to your code, then make it so when the event you want to be permanent is called (you can check which event is triggered by checking the eventName parameter), you set a SaveData variable (preferably a bool that gets set to true). also, make sure that variable is initialized near the top of the file to make sure it's never nil. then, in onStart, check that SaveData variable to see if it was set, and if it was, trigger the event you want with triggerEvent. it'll look something like this

Code: Select all

-- initialize the saveData variable if it isn't already
SaveData.eventTriggered = SaveData.eventTriggered or false

function onStart()
	if SaveData.eventTriggered then
		triggerEvent("[name of the event you want]")
	end
end

function onEvent(eventName)
	if eventName == "[name of the event you want]" then
		SaveData.eventTriggered = true
	end
end
here's some links in the documentation about what i used if you want to learn more:
https://docs.codehaus.moe/#/reference/lunalua-events
https://docs.codehaus.moe/#/concepts/savedata-gamedata


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 0 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari