deice wrote: ↑Sat Apr 27, 2024 9:30 am
this is because you're calling "getActive" on an already-instanced checkpoint instead of statically on the Checkpoint class. the code i posted is meant to be used verbatim; getActive will return the currently active checkpoint within the level,
whichever one that may be.
Marioman2007 wrote: ↑Sat Apr 27, 2024 9:33 am
Checkpoint.getActive() returns the currently active checkpoint.
Try this code and see if it works as intended.
It's kind of funny, now that you see it, it kind of makes sense. If CP1 is the active checkpoint, then do that... yes, you're always smarter afterwards.
Unfortunately, after an intensive thinking phase (I actually really mean it
), I came to the realization that this is not at all useful for the implementation of my solution approach at all (sorry to both of you).
That is because I already made use of
Code: Select all
function onStart()
...
if player.x == ... and player.section == ... then
--do stuff
end
...
The thing is I still have my other project in the pipeline where I wanted the show the player some kind of "intro image" at the beginning (SMB1 you know).
Yes, Emral might remember - if you read it. To be honest however it did not work out well and caused annoying random bugs here and there (sometimes the intro image did not appear in the first place e.g.).
Anyway: I figured a solution, it looks terrible, you might laugh and shake your head, facepalm and whatever. But it seems to work (Hint: If there is a LESS complicated way to realize it, please tell me)
I was surprised BTW it is not possible to create a warp like creating a checkpoint, at least I could not find anything like that.
Code: Select all
--------------------------------------------------
-- Level code
-- Created 16:34 2024-4-27
--------------------------------------------------
local checkpoints = require("checkpoints")
local cp1 = checkpoints.create{x = -179296, y = -180128, section = 1}
local cp2 = checkpoints.create{x = -177728, y = -180128, section = 1}
function onStart()
local warpStart1Layer = Layer.get("warpStart1")
local warpStart2Layer = Layer.get("warpStart2")
local warpStart3Layer = Layer.get("warpStart3")
warpStart1Layer:show(true)
warpStart2Layer:hide(true)
warpStart3Layer:hide(true)
local warpCP1Layer = Layer.get("warpCheckpoint1")
local warpCP2Layer = Layer.get("warpCheckpoint2")
warpCP1Layer:hide(true)
warpCP2Layer:hide(true)
--checkpoint 1
if player.x == -179308 and player.section == 1 then
Routine.run(checkPoint1R)
end
--checkpoint 2
if player.x == -177740 and player.section == 1 then
Routine.run(checkPoint2R)
end
end
function onTick()
--Text.print(player.x, 100, 100)
end
function checkPoint1R()
local warpCP1Layer = Layer.get("warpCheckpoint1")
warpCP1Layer:show(true)
local warpStart2Layer = Layer.get("warpStart2")
local warpStart1Layer = Layer.get("warpStart1")
warpStart2Layer:show(true)
warpStart1Layer:hide(true)
Routine.waitSeconds(1.0, true)
warpCP1Layer:hide(true)
end
function checkPoint2R()
local warpCP2Layer = Layer.get("warpCheckpoint2")
warpCP2Layer:show(true)
local warpStart3Layer = Layer.get("warpStart3")
local warpStart1Layer = Layer.get("warpStart1")
warpStart3Layer:show(true)
warpStart1Layer:hide(true)
Routine.waitSeconds(1.0, true)
warpCP2Layer:hide(true)
end
Also as a download here:
https://file.io/LaR8glu3ZVHw
or
https://www.file-upload.net/download-15 ... f.zip.html
or
https://fastupload.io/TQrQnRQi1NO0aON/file
Edit: Ok, it was NOT for nothing as this is a little bit less complicated indeed
Code: Select all
...
--checkpoint 1
if Checkpoint.getActive() == cp1 then
Routine.run(checkPoint1R)
end
--checkpoint 2
if Checkpoint.getActive() == cp2 then
Routine.run(checkPoint2R)
end
...
works the same