How to make things only happen once in a level?

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

Moderator: Userbase Moderators

Mal8rk
Snifit
Snifit
Posts: 217
Joined: Mon Oct 25, 2021 11:04 pm
Flair: English Speaking Spanish Speaker
Pronouns: He/Him
Contact:

How to make things only happen once in a level?

Postby Mal8rk » Mon Mar 07, 2022 9:42 am

I've seen many episodes do this in which something only happens once in a level, and can't be repeated again in an episode

The best example of this is Subzero Heroes, in which cutscenes only happen one time, and can't be repeated again

So how can I make it myself? I think it requires SaveData, but that's all I know

Note: I want the code to make it so that if you die, the thing that is intended to happen once in that episode's level does not appear. I want to make it so that the thing that is intended to happen once in that episode's level only appears when the level is finished by any clearing bethod

Shodax
Bot
Bot
Posts: 53
Joined: Sat Feb 05, 2022 2:24 pm
Pronouns: he

Re: How to make things only happen once in a level?

Postby Shodax » Mon Mar 07, 2022 2:21 pm

I'm also looking for something similar. It would be good to know how to do it so that once a level is finished you can not re-enter the

cato
Volcano Lotus
Volcano Lotus
Posts: 564
Joined: Thu Aug 24, 2017 3:06 am
Flair: Koishi enjoyer
Contact:

Re: How to make things only happen once in a level?

Postby cato » Sat Mar 19, 2022 9:52 am

Use savedata/gamedata

A quick example for boss cutscenes

Code: Select all

GameData[Level.filename()] = GameData[Level.filename()] or {}
local gameData = GameData[Level.filename()]

function onstart()
     -- Define a variable
     if gameData.x == nil then
          gameData.x = false
     end
end

function onEvent(eventName)

     -- Saving the progress that you already unlocked the boss fight
     if eventName == "Phrase 1" then
          gameData.x = true
     end

     -- When you first fight the boss, you go through a cutscene. After that, the cutscene is skipped and directly goes to the boss fight
     if eventName == "Boss Trigger" then
           if gameData.x == true then
                 triggerEvent("Phrase 1")
           else triggerEvent("Cutscene") end
     end
end
You can also use it to do different things, such as unlocking a secret path after collecting every red coins, even after dying or restarting.


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 3 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari