use Misc.saveGame()
Once you reach a checkpoint the "global value" gets changed and because different layers get hidden or shown, it would mean the player would get teleported to the "last reached" checkpoint.Code:
local Routine = API.load("Routine")local inputs2 = API.load("inputs2")local myGameDatadolocal levelstartwarpGameData = GameData[levelstartwarp] or {}myGameData = GameData[levelstartwarp]endfunction onStart() local defaultLayer = Layer.get("Default")defaultLayer:show(true)local lvlstartLayer = Layer.get("LevelScreenPlattform")lvlstartLayer:show(true)endfunction onTick() Text.print(myGameData, 100, 100)if player.y < -180032 and player.section == 0 thenRoutine.run(levelStartScreen)endif player.section == 1 thenRoutine.run(IncreaseCounter)endfunction levelStartScreen()local lvlstartLayer = Layer.get("LevelScreenPlattform")inputs2.locked[1].all = trueplayer.speedX = 0lvlstartLayer.speedY = 2.5Routine.waitFrames(200)lvlstartLayer.speedY = 0inputs2.locked[1].all = falseendfunction IncreaseCounter()myGameData = myGameData +1end
In case context is needed: I try to integrate some kind of "fake checkpoints" (without powerup and sfx).
At the beginning of the level a fake loading screen is visible (works fine, not the problem here) and after a bunch of seconds the player is supposed to get warped to the last "checkpoint". HOWEVER I need a variable which does store the right and last value instead to reset every time after the player death.
Since this should work like in the origional SMB without savepoints and worldmap I need a variable which does save after player death.
I want to use GameData because if you close SMBX you have to restart with the first level
(I plan to use Auto-loading next level after winning • levellist.lua
myGameData or levelstartwarp could be used beyond the corresponding level as follows.
World 1-1: Player reaches first "checkpoint" -> Value: 1
player dies
Value stays 1
player restarts at last checkpoint
player dies (before next checkpoint)
Value stays 1, no progress of the player
player reaches second "Checkpoint" -> Value: 2
Player reaches World 1-2 (Value for safety reasons: 3)
player dies
Value still 3, player restarts from levelstart of World 1-2
player reaches first "Checkpoint" (of 1-2): Value 4
player dies
player restarts at last checkpoint (first one of 1-2)
...
I think you get it now
I am honest: I do not really know what I am doing here. I barely understood some basic things from the Demolevels and and try to find the grain here like a blind hen. I hope that by showing something here, someone will be willing to tell me how it works. These documentaries are a bit difficult for people like me to understand. I'm not really the scripting type (never have been in my life).
Statistics: Posted by LooKiCH — Sat Jan 13, 2024 1:38 pm