Page 1 of 1

How to save triggered events

Posted: Fri Feb 14, 2025 1:36 pm
by AlphaBlue1011
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?

Re: How to save triggered events

Posted: Fri Feb 14, 2025 2:17 pm
by cold soup
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