Need help with lua? - LunaLua General Help

Post here for help and support regarding LunaLua and SMBX2's libraries and features.
Marioman2007
Lakitu
Lakitu
Posts: 466
Joined: Tue Aug 25, 2020 3:19 am
Flair: Dr. Bones
Pronouns: He/Him

Re: Need help with lua? - LunaLua General Help

Postby Marioman2007 » Sun Mar 24, 2024 11:02 am

Does "if sectionIdx == 1 then" work for your case?

Just_Thomas
Snifit
Snifit
Posts: 233
Joined: Sat Dec 16, 2023 3:32 am
Pronouns: he/him

Re: Need help with lua? - LunaLua General Help

Postby Just_Thomas » Sun Mar 24, 2024 11:36 am

Marioman2007 wrote:
Sun Mar 24, 2024 11:02 am
Does "if sectionIdx == 1 then" work for your case?
I was THAT close? Eeeeh... yes, this does the trick, I just checked and tested.
Thanks and BTW: Forgot about you in that moment, you also helped me quite a lot. (:

mariobrigade2018
Spike
Spike
Posts: 275
Joined: Wed May 24, 2023 7:00 pm
Flair: Normie in coding who dreams of making a Mario game
Pronouns: he/him

Re: Need help with lua? - LunaLua General Help

Postby mariobrigade2018 » Tue Apr 16, 2024 3:36 pm

How do I make RNG non-inclusive?

Just_Thomas
Snifit
Snifit
Posts: 233
Joined: Sat Dec 16, 2023 3:32 am
Pronouns: he/him

Re: Need help with lua? - LunaLua General Help

Postby Just_Thomas » Fri Apr 26, 2024 2:51 pm

Is it actually possible to work with something like this? (Hint: It is not actual real working code, it is only written that way so that it is immediately clear what I mean/try to say):

Code: Select all

function onStart()

	if checkpoint1:collect() == true then
     ...
	end
end
During 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.
Since I have too little knowledge, I hope someone from the development team can tell me briefly and concisely whether this works.

deice
Volcano Lotus
Volcano Lotus
Posts: 548
Joined: Fri Jul 23, 2021 7:35 am

Re: Need help with lua? - LunaLua General Help

Postby deice » Sat Apr 27, 2024 6:43 am

Just_Thomas wrote:
Fri Apr 26, 2024 2:51 pm
During 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.
you're probably looking for something like this:

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
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.

Just_Thomas
Snifit
Snifit
Posts: 233
Joined: Sat Dec 16, 2023 3:32 am
Pronouns: he/him

Re: Need help with lua? - LunaLua General Help

Postby Just_Thomas » Sat Apr 27, 2024 7:37 am

deice wrote:
Sat Apr 27, 2024 6:43 am
Just_Thomas wrote:
Fri Apr 26, 2024 2:51 pm
During 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.
you're probably looking for something like this:

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
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.
First, thanks for your reply as usual.
Actually I wouldn`t have guessed the docu is NOT finished (so it is updated to beta 5 as stated on the "welcome Screen" but old stuff is still missing?).

Code: Select all

local checkpoints = require("checkpoints")
local cp1 = checkpoints.create{x = -103104, y = -100128, section = 5}
So, I had a checkpoint already (still thanking Emral for telling me how to do that).

ok, I then adapted the code for my test:

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
	
...
	
(yes, the routine mentioned does exist as well and does work properly)
Just starting the level gives me this error
Image

deice
Volcano Lotus
Volcano Lotus
Posts: 548
Joined: Fri Jul 23, 2021 7:35 am

Re: Need help with lua? - LunaLua General Help

Postby deice » Sat Apr 27, 2024 9:30 am

Just_Thomas wrote:
Sat Apr 27, 2024 7:37 am
Just starting the level gives me this error
Image
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
Lakitu
Lakitu
Posts: 466
Joined: Tue Aug 25, 2020 3:19 am
Flair: Dr. Bones
Pronouns: He/Him

Re: Need help with lua? - LunaLua General Help

Postby Marioman2007 » Sat Apr 27, 2024 9:33 am

Checkpoint.getActive() returns the currently active checkpoint.
Try this code and see if it works as intended.

Code: Select all

local cp1 = Checkpoint{x = -103104, y = -100128, section = 5}

function onStart()
	if Checkpoint.getActive() == cp1 then
		Routine.run(VineInSky)
	end
end

Just_Thomas
Snifit
Snifit
Posts: 233
Joined: Sat Dec 16, 2023 3:32 am
Pronouns: he/him

Re: Need help with lua? - LunaLua General Help

Postby Just_Thomas » Sat Apr 27, 2024 12:02 pm

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 :D), 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
Image

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 :)


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 2 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari