Advertisement
Enjl

Simple checkpoints

Apr 9th, 2023
811
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.07 KB | None | 0 0
  1. -- Initialize GameData, cross-playthrough variables, for this level. This avoids conflicts with GameData of other levels.
  2. GameData[Level.filename()] = GameData[Level.filename()] or {}
  3. -- Initialize the checkpoint variable
  4. GameData[Level.filename()].checkpoint = GameData[Level.filename()].checkpoint or 0
  5.  
  6. -- When the level starts, trigger a SMBX event by name, based on which checkpoint we are at.
  7. function onStart()
  8.     local checkpoint = GameData[Level.filename()].checkpoint
  9.    
  10.     if checkpoint == 0 then
  11.         triggerEvent("startFight")
  12.     elseif checkpoint == 1 then
  13.         triggerEvent("startCP1")
  14.     elseif checkpoint == 2 then
  15.         triggerEvent("startCP2")
  16.     end
  17. end
  18.  
  19. -- In a SMBX event, trigger the events named below to collect a checkpoint.
  20. function onEvent(eventName)
  21.     if eventName == "collectCP1" then
  22.         GameData[Level.filename()].checkpoint = 1
  23.     elseif eventName == "collectCP2" then
  24.         GameData[Level.filename()].checkpoint = 2
  25.     end
  26. end
  27.  
  28. -- Reset the checkpoint after winning
  29. function onExit()
  30.     if Level.winState() > 0 then
  31.         GameData[Level.filename()].checkpoint = 0
  32.     end
  33. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement