Need help with lua? - LunaLua General Help

Post here for help and support regarding LunaLua and SMBX2's libraries and features.
Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9718
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Need help with lua? - LunaLua General Help

Postby Emral » Wed Aug 24, 2022 7:55 pm

deice wrote:
Wed Aug 24, 2022 4:43 pm
however, if the lua file itself is right in your episode folder too (as opposed to a level's custom folder), the resolveFile() call is superfluous and can be removed:

Code: Select all

Graphics.loadImage("Folder/MyItem.png")
To my knowledge this is untrue, as all lua looks in the level folder of the current level first.

LunarCatUSA
Hoopster
Hoopster
Posts: 115
Joined: Sat Mar 06, 2021 9:56 am
Flair: Soda-Butler

Re: Need help with lua? - LunaLua General Help

Postby LunarCatUSA » Wed Aug 24, 2022 10:24 pm

Thanks, now is it possible to trigger a door's opening effect without the player warping in front of it?

Like when the player is physically colliding with the door and does a certain action, how would I go about playing its opening effect?

And yes, I can confirm Enji is right.

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

Re: Need help with lua? - LunaLua General Help

Postby deice » Thu Aug 25, 2022 6:07 am

Enjl wrote:
Wed Aug 24, 2022 7:55 pm
To my knowledge this is untrue, as all lua looks in the level folder of the current level first.
my bad, i hadn't actually bothered to check whether the loadImage() call itself returned nil or not, haha~
LunarCatUSA wrote: Thanks, now is it possible to trigger a door's opening effect without the player warping in front of it?
the door effects work like any other ones to my knowledge, just spawning one at the door's location should be fine.

LunarCatUSA
Hoopster
Hoopster
Posts: 115
Joined: Sat Mar 06, 2021 9:56 am
Flair: Soda-Butler

Re: Need help with lua? - LunaLua General Help

Postby LunarCatUSA » Thu Aug 25, 2022 4:38 pm

Okay so the code I have here:

Code: Select all

function onTick()
DynamicBackgrounds = BGO.get()
Interactibles = NPC.get(465)
-- Can the player hide here? --
	for k,v in ipairs(Interactibles) do
    	if v.data._settings._global.hidingSpot and (colliders.collide(v, player)) and player.downKeyPressing == true then
    		playerhiding = true
    		SFX.play("Hide_Wood1.wav")
    		for kk,vv in ipairs(DynamicBackgrounds) do
    			if colliders.collide(vv, player) and vv.id == 87 then
    				spawnhideanim = Effect.spawn(55, vv)
    				spawnhideanim.x = vv.x
    				spawnhideanim.y = vv.y
    			end
    		end
    	end
    end
And the code works up until effect spawn where I try the command, but it doesn't spawn there at all.

Am I calling the effect incorrectly? Or is this another thing where there's an extra step involved?

Added in 4 hours 54 minutes 23 seconds:
Okay, so other effects spawn but not doors for some reason. That's strange.

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

Re: Need help with lua? - LunaLua General Help

Postby deice » Fri Aug 26, 2022 7:51 am

LunarCatUSA wrote:
Thu Aug 25, 2022 9:33 pm
And the code works up until effect spawn where I try the command, but it doesn't spawn there at all.

Am I calling the effect incorrectly? Or is this another thing where there's an extra step involved?

Added in 4 hours 54 minutes 23 seconds:
Okay, so other effects spawn but not doors for some reason. That's strange.
i ran the code myself and the door effect does indeed spawn, however for some reason it isn't getting drawn (it's not that it's somehow getting drawn below the door either, i tried spawning it in other locations, same results). no idea what could be causing this, could a dev maybe chime in?

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9718
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Need help with lua? - LunaLua General Help

Postby Emral » Fri Aug 26, 2022 10:11 am

Unsure, but it might make sense to simply copy the door effect from config/effects into the custom range and use that. other effects like underwater effects are known to be finnicky to spawn, so perhaps doors are the same.

LunarCatUSA
Hoopster
Hoopster
Posts: 115
Joined: Sat Mar 06, 2021 9:56 am
Flair: Soda-Butler

Re: Need help with lua? - LunaLua General Help

Postby LunarCatUSA » Fri Aug 26, 2022 1:08 pm

Hmmm.... I edited the txt file for effect-55 to become similar to the explosion effect-108 because that one actually works, but I guess that didn't do it. I may just edit one of the others to look like the door one and alter its effect text file.

Added in 7 hours 7 minutes 29 seconds:
Oh also, is it possible to have an enemy active off-screen?

I'm trying to give an enemy a "chase" mechanic similar to Phanto and I'm curious as to what makes it function off screen.

LunarCatUSA
Hoopster
Hoopster
Posts: 115
Joined: Sat Mar 06, 2021 9:56 am
Flair: Soda-Butler

Re: Need help with lua? - LunaLua General Help

Postby LunarCatUSA » Sat Aug 27, 2022 3:26 pm

Oh, I found Enji's spawnzone code. I wonder if I should use that for my enemy's code.

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

Re: Need help with lua? - LunaLua General Help

Postby deice » Sat Aug 27, 2022 3:40 pm

LunarCatUSA wrote:
Fri Aug 26, 2022 8:15 pm
Oh also, is it possible to have an enemy active off-screen?

I'm trying to give an enemy a "chase" mechanic similar to Phanto and I'm curious as to what makes it function off screen.
you can just set it's despawnTimer to a positive value.

(as for the effects, as enjl said, all you need to do is make a custom effect, copy "effect-55.txt" from "data/config/effects" and rename it to fit the ID you need)

LunarCatUSA
Hoopster
Hoopster
Posts: 115
Joined: Sat Mar 06, 2021 9:56 am
Flair: Soda-Butler

Re: Need help with lua? - LunaLua General Help

Postby LunarCatUSA » Sat Aug 27, 2022 10:41 pm

Thanks, I take it that it doesn't work if the enemy is in a different section? If that's the case, I'll probably just make a room change code for the 'search-for-the-player code' within the script of the level itself.

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

Re: Need help with lua? - LunaLua General Help

Postby deice » Sun Aug 28, 2022 7:00 am

LunarCatUSA wrote:
Sat Aug 27, 2022 10:41 pm
Thanks, I take it that it doesn't work if the enemy is in a different section? If that's the case, I'll probably just make a room change code for the 'search-for-the-player code' within the script of the level itself.
a good example of how a basegame npc handles section changing can be found in the phanto ai script ("data/npc/ai/phantos.lua") from around line 205.

LunarCatUSA
Hoopster
Hoopster
Posts: 115
Joined: Sat Mar 06, 2021 9:56 am
Flair: Soda-Butler

Re: Need help with lua? - LunaLua General Help

Postby LunarCatUSA » Sun Aug 28, 2022 9:38 pm

Hmmm... yeah, I'm looking at that line of phanto code where it says 'StubbornTarget', I just gotta find out what keeps the dude active and moving in other sections while the player is in another one. I'll probably find it eventually.

Added in 1 hour 46 minutes 55 seconds:
Worst case scenario, I could always just keep everything to one section and just make it big for the rooms and warps. Change backgrounds and music via scripts.

LunarCatUSA
Hoopster
Hoopster
Posts: 115
Joined: Sat Mar 06, 2021 9:56 am
Flair: Soda-Butler

Re: Need help with lua? - LunaLua General Help

Postby LunarCatUSA » Mon Aug 29, 2022 12:33 pm

Question, is it possible to spawn a light point with specific attributes?

I want to spawn an instance of npc-668, the light, on a certain npc to make a 'glowing eye' feel. But I want to have the light span out to a certain radius and adjust its color accordingly.

I know how to spawn the npc, I just want to know how to make these adjustments, if it's possible.

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

Re: Need help with lua? - LunaLua General Help

Postby deice » Mon Aug 29, 2022 1:00 pm

LunarCatUSA wrote:
Mon Aug 29, 2022 12:33 pm
Question, is it possible to spawn a light point with specific attributes?
yes:

Code: Select all

local v = NPC.spawn(668, ...)
local light = v.data._basegame.light
"light" can then be accessed by any other light source object.

LunarCatUSA
Hoopster
Hoopster
Posts: 115
Joined: Sat Mar 06, 2021 9:56 am
Flair: Soda-Butler

Re: Need help with lua? - LunaLua General Help

Postby LunarCatUSA » Mon Aug 29, 2022 1:16 pm

Alright, I'll try that. I think Enji made a video explaining how to put a light on things but for some reason,
local EnemyLight = darkness.Light(0,0,128,1,Color.white)
gives an error message and I can't find anything in the wohlsoft or codehaus guides explaining lights all that well.

I do know that I can attach em with the :attach() command.

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

Re: Need help with lua? - LunaLua General Help

Postby deice » Mon Aug 29, 2022 1:49 pm

LunarCatUSA wrote:
Mon Aug 29, 2022 1:16 pm
local EnemyLight = darkness.Light(0,0,128,1,Color.white)
"darkness" should be "Darkness", capital; and "Light" should be "light", lowercase. you no longer need to explicitly load the library.

LunarCatUSA
Hoopster
Hoopster
Posts: 115
Joined: Sat Mar 06, 2021 9:56 am
Flair: Soda-Butler

Re: Need help with lua? - LunaLua General Help

Postby LunarCatUSA » Mon Aug 29, 2022 2:23 pm

Alright, I make the light
local biolum = Darkness.light(0,0,128,1,false,Color.white)
and then under onStart() I add
biolum:Attach(player)
end

and the player is still in the dark. Does it need to be enabled like an effect or is there another reason?

Added in 10 hours 10 minutes 31 seconds:
Okay, so here's my code for my NPC.

Code: Select all

Warppoints = Warp.get()
	PlayersPath = {}
	-- Warps it already passed through --
	AlreadyCameFrom = {}
	State = {"patrol", "search", "chase"}
	if v.isValid == true then
		Actpattern = State[1]
	end
	-- Patrol, this enemy is searching rooms for the player, it is in the same section as the player --
		if Actpattern == State[1] then
			if v.direction == -1 then
				v.speedX = -1
			elseif v.direction == 1 then
				v.speedX = 1
			end
			for k, w in ipairs(Warppoints) do
				if colliders.collide(v, w) and w ~= AlreadyCameFrom[1] then
					headsortails = RNG.randomInt(0,100)
					if headsortails <= 30 then
						v:transform(897,true,true)
						v.x=w.entranceX
						v.y=w.entranceY-32
						if AlreadyCameFrom[1] ~= nil then
							table.remove(AlreadyCameFrom)
						end
						table.insert(AlreadyCameFrom, w)
					end
				elseif colliders.collide(v, w) and w == AlreadyCameFrom[1] then
					headsortails = RNG.randomInt(0,100)
					if headsortails <= 5 then
						v:transform(897,true,true)
						v.x=w.entranceX
						v.y=w.entranceY-32
						table.remove(AlreadyCameFrom)
						table.insert(AlreadyCameFrom, w)
					end
				end
			end
		end
Basically, I want to make the code so that my enemy will pass a warp point and if it isn't the warppoint it exited, it has a 30% chance to enter it and if it is the warppoint it exited, it has a 5% chance to enter. Entering results in it spawning a smaller version of itself in the form of an animation that enters the door and spawns it on the end-side. That part is all done and good in another code but here's the issue; it gives an error message named "Unknown collider type". Does the collider not work with warp points?

Added in 9 hours 7 minutes 30 seconds:
Hmm... looks like the warp list perpetually defines all warp entrances and exits as NIL. I wonder if it shouldn't be under OnTick()

Added in 6 minutes 48 seconds:
Oh wait, x and y aren't actual variables for the warps, I need to check entranceX and entranceY

Marioman2007
Lakitu
Lakitu
Posts: 465
Joined: Tue Aug 25, 2020 3:19 am
Flair: Dr. Bones
Pronouns: He/Him

Re: Need help with lua? - LunaLua General Help

Postby Marioman2007 » Tue Aug 30, 2022 10:24 am

LunarCatUSA wrote:
Tue Aug 30, 2022 9:48 am
Alright, I make the light
local biolum = Darkness.light(0,0,128,1,false,Color.white)
and then under onStart() I add
biolum:Attach(player)
end

and the player is still in the dark. Does it need to be enabled like an effect or is there another reason?
use onDraw()

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9718
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Need help with lua? - LunaLua General Help

Postby Emral » Tue Aug 30, 2022 11:11 am

Marioman2007 wrote:
Tue Aug 30, 2022 10:24 am
LunarCatUSA wrote:
Tue Aug 30, 2022 9:48 am
Alright, I make the light
local biolum = Darkness.light(0,0,128,1,false,Color.white)
and then under onStart() I add
biolum:Attach(player)
end

and the player is still in the dark. Does it need to be enabled like an effect or is there another reason?
use onDraw()
no? the point of the attach method is that it handles the position updates for you if done once.

https://docs.codehaus.moe/#/handbook/lu ... d-lighting
Lights need to be added to a darkness field explicitly, via Darkness.addLight(biolum)

Marioman2007
Lakitu
Lakitu
Posts: 465
Joined: Tue Aug 25, 2020 3:19 am
Flair: Dr. Bones
Pronouns: He/Him

Re: Need help with lua? - LunaLua General Help

Postby Marioman2007 » Tue Aug 30, 2022 12:02 pm

Enjl wrote:
Tue Aug 30, 2022 11:11 am
Marioman2007 wrote:
Tue Aug 30, 2022 10:24 am
use onDraw()
no? the point of the attach method is that it handles the position updates for you if done once.

https://docs.codehaus.moe/#/handbook/lu ... d-lighting
Lights need to be added to a darkness field explicitly, via Darkness.addLight(biolum)
ohh, glad to know now lol
I thought it was just a function that sets the position for one frame


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 0 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari