Re: Need help with lua? - LunaLua General Help
Posted: Sun Mar 24, 2024 11:02 am
Does "if sectionIdx == 1 then" work for your case?
Forums for SMBX
https://www.smbxgame.com/forums/
I was THAT close? Eeeeh... yes, this does the trick, I just checked and tested.
Code: Select all
function onStart()
if checkpoint1:collect() == true then
...
end
end
you're probably looking for something like this:Just_Thomas wrote: ↑Fri Apr 26, 2024 2:51 pmDuring normal gameplay, the SMW-typical checkpoint is saved as "activated", so I'm wondering whether you could work with something like this and query it at the start of the game.
Code: Select all
function onStart()
local c = Checkpoint.getActive()
-- the variable c now holds a reference to the active checkpoint object, or nil if there's no active checkpoint in the current level
if(c) then
-- execute code here if the checkpoint exists
end
end
First, thanks for your reply as usual.deice wrote: ↑Sat Apr 27, 2024 6:43 amyou're probably looking for something like this:Just_Thomas wrote: ↑Fri Apr 26, 2024 2:51 pmDuring normal gameplay, the SMW-typical checkpoint is saved as "activated", so I'm wondering whether you could work with something like this and query it at the start of the game.unfortunately i don't think the checkpoint class documentation is finished, but if memory serves me right you should be able to at least poll for its position and section.Code: Select all
function onStart() local c = Checkpoint.getActive() -- the variable c now holds a reference to the active checkpoint object, or nil if there's no active checkpoint in the current level if(c) then -- execute code here if the checkpoint exists end end
Code: Select all
local checkpoints = require("checkpoints")
local cp1 = checkpoints.create{x = -103104, y = -100128, section = 5}
Code: Select all
function onStart()
local c1 = cp1.getActive()
-- the variable c now holds a reference to the active checkpoint object, or nil if there's no active checkpoint in the current level
if(c1) then
Routine.run(VineInSky)
end
...
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.
Code: Select all
local cp1 = Checkpoint{x = -103104, y = -100128, section = 5}
function onStart()
if Checkpoint.getActive() == cp1 then
Routine.run(VineInSky)
end
end
deice wrote: ↑Sat Apr 27, 2024 9:30 amthis 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.
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.Marioman2007 wrote: ↑Sat Apr 27, 2024 9:33 amCheckpoint.getActive() returns the currently active checkpoint.
Try this code and see if it works as intended.
Code: Select all
function onStart()
...
if player.x == ... and player.section == ... then
--do stuff
end
...
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
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
...