Page 1 of 1

How to make things only happen once in a level?

Posted: Mon Mar 07, 2022 9:42 am
by Mal8rk
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

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

Posted: Mon Mar 07, 2022 2:21 pm
by Shodax
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

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

Posted: Sat Mar 19, 2022 9:52 am
by cato
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.