GameData: Save value of variable after player death
Posted: Sat Jan 13, 2024 10:09 am
Code: Select all
local Routine = API.load("Routine")
local inputs2 = API.load("inputs2")
local myGameData
do
local levelstartwarp
GameData = GameData[levelstartwarp] or {}
myGameData = GameData[levelstartwarp]
end
function onStart()
local defaultLayer = Layer.get("Default")
defaultLayer:show(true)
local lvlstartLayer = Layer.get("LevelScreenPlattform")
lvlstartLayer:show(true)
end
function onTick()
Text.print(myGameData, 100, 100)
if player.y < -180032 and player.section == 0 then
Routine.run(levelStartScreen)
end
if player.section == 1 then
Routine.run(IncreaseCounter)
end
function levelStartScreen()
local lvlstartLayer = Layer.get("LevelScreenPlattform")
inputs2.locked[1].all = true
player.speedX = 0
lvlstartLayer.speedY = 2.5
Routine.waitFrames(200)
lvlstartLayer.speedY = 0
inputs2.locked[1].all = false
end
function IncreaseCounter()
myGameData = myGameData +1
end
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).