Page 1 of 1

Milky Way Wishes style game (LUA REQUEST)

Posted: Mon Mar 22, 2021 12:28 am
by CommanderNemex
Can someone create a system where you have to beat multiple levels in any order you want to unlock something?. Just like in Milky Way Wishes and the fourth world of Kirby Star Allies. For example, there is an island. Mario beats 5 levels he picked accordingly, and suddenly the Bowser head cave (From SMW), appears. Thank you.

Re: Milky Way Wishes style game (LUA REQUEST)

Posted: Mon Mar 22, 2021 4:18 am
by Emral
You can use SaveData, onTickEnd and onStart for this:

Every time you beat an area for the first time, remember it in SaveData (in onTickEnd of episode-wide luna.lua):

Code: Select all

-- Initialize if nil
SaveData.beatenLevel = SaveData.beatenLevel or {}
SaveData.numberOfLevelsBeaten = SaveData.numberOfLevelsBeaten or 0

function onTickEnd()
	-- Check if the current level is beaten
	if Level.winState() > 0 and not SaveData.beatenLevel[Level.filename()] then
		SaveData.beatenLevel[Level.filename()] = true
		SaveData.numberOfLevelsBeaten = SaveData.numberOfLevelsBeaten + 1
	end
end
The level containing the entrance to the new area must then just trigger an event in the level if the conditions are met (level-wide luna.lua):

Code: Select all

function onStart()
	if SaveData.numberOfLevelsBeaten == 9 then
		triggerEvent("unlockLastArea")
	end
end
This will cause the unlockLastArea-Event to be called, where you can show/hide relevant layers.