Milky Way Wishes style game (LUA REQUEST)

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

Moderator: Userbase Moderators

CommanderNemex
2025 Egg Hunter
2025 Egg Hunter
Posts: 6
Joined: Sat Mar 13, 2021 8:34 pm
Pronouns: He/Him

Milky Way Wishes style game (LUA REQUEST)

Postby CommanderNemex » Mon Mar 22, 2021 12:28 am

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.

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

Re: Milky Way Wishes style game (LUA REQUEST)

Postby Emral » Mon Mar 22, 2021 4:18 am

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.


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 1 guest

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari