-- Initialize GameData, cross-playthrough variables, for this level. This avoids conflicts with GameData of other levels. GameData[Level.filename()] = GameData[Level.filename()] or {} -- Initialize the checkpoint variable GameData[Level.filename()].checkpoint = GameData[Level.filename()].checkpoint or 0 -- When the level starts, trigger a SMBX event by name, based on which checkpoint we are at. function onStart() local checkpoint = GameData[Level.filename()].checkpoint if checkpoint == 0 then triggerEvent("startFight") elseif checkpoint == 1 then triggerEvent("startCP1") elseif checkpoint == 2 then triggerEvent("startCP2") end end -- In a SMBX event, trigger the events named below to collect a checkpoint. function onEvent(eventName) if eventName == "collectCP1" then GameData[Level.filename()].checkpoint = 1 elseif eventName == "collectCP2" then GameData[Level.filename()].checkpoint = 2 end end -- Reset the checkpoint after winning function onExit() if Level.winState() > 0 then GameData[Level.filename()].checkpoint = 0 end end