Need help with lua? - LunaLua General Help

This is the place for discussion and support for LunaLua and related modifications and libraries.

Moderator: Userbase Moderators

Forum rules
Before you make a topic/post, consider the following:
-Is there a topic for this already?
-Is your post on topic/appropriate?
-Are you posting in the right forum/following the forum rules?
Quantumenace
Chain Chomp
Chain Chomp
Posts: 308
Joined: Mon Dec 28, 2015 2:17 am

Re: Need help with lua? - LunaLua General Help

Postby Quantumenace » Mon Apr 03, 2017 4:13 am

Devan2002: There is the event function onNPCKill(Event eventObj, NPC killedNPC, number killReason) that runs when an NPC is killed. The function arguments are arbitrarily named variables that are automatically assigned the relevant value and can be referenced.

Example:

Code: Select all

function onNPCKill(e, killedNPC, killtype)
    if killedNPC.id == 210 then
        .............................
    end
end

MosaicMario: You have two functions named onTick and that won't work. (and in addition your second one is spelled with a capital O and won't be used as an event anyway.)

Either put the content in the same onTick, or put it in separate functions that are both called in onTick().

TDK
Phanto
Phanto
Posts: 1440
Joined: Wed Nov 11, 2015 12:26 pm
Flair: Retired

Re: Need help with lua? - LunaLua General Help

Postby TDK » Mon Apr 03, 2017 9:56 am

Is there any way to make a block chase you throughout the entire level?
I tried it with chasing koopa para-troopa, but it goes off-screen and disappear.

PersonNamedUser
Reznor
Reznor
Posts: 2882
Joined: Fri Feb 27, 2015 8:07 pm

Re: Need help with lua? - LunaLua General Help

Postby PersonNamedUser » Mon Apr 03, 2017 11:05 am

IT. NEVER. ENDS.
Now what's wrong with it?
Image

Code: Select all

local haveBoosted = false;
local haveBoostedDown = false;

function onLoop()
	if player:mem(0x146, FIELD_WORD) == 2 then
		HaveBoosted = false;
		HaveBoostedDown = false;
	end
end

function onStart()
     Level.loadPlayerHitBoxes(4, 1, "toad-1.ini")
	 Level.loadPlayerHitBoxes(4, 2, "toad-2.ini")
	 Level.loadPlayerHitBoxes(4, 3, "toad-3.ini")
	 Level.loadPlayerHitBoxes(4, 4, "toad-4.ini")
	 Level.loadPlayerHitBoxes(4, 5, "toad-5.ini")
	 Level.loadPlayerHitBoxes(4, 6, "toad-6.ini")
     Level.loadPlayerHitBoxes(4, 7, "toad-7.ini")
end

function onTick()
		if player:mem(0x146, FIELD_WORD == 0) and (player:mem(0xF4, FIELD_WORD) == true) and player.rightKeyPressing then 
		if haveBoosted == false then
		player.speedX = -5
		Audio.playSFX("dash.wav")
		do haveBoosted = true;
		end
		elseif player:mem(0x146, FIELD_WORD == 0) and (player:mem(0xF4, FIELD_WORD) == true) and player.leftKeyPressing then 
		if haveBoosted == false then
		player.speedX = 5
		Audio.playSFX("dash.wav")
		do haveBoosted = true;
		end
		elseif player:mem(0x146, FIELD_WORD == 0) and (player:mem(0xF4, FIELD_WORD) == true) and player.downKeyPressing then 
		if haveBoostedDown == false then
		player.speedY = 5
		Audio.playSFX("dash.wav")
		do haveBoostedDown = true;
		do haveBoosted = true;
						end
					end
				end
			end
		end
	end
end

TDK
Phanto
Phanto
Posts: 1440
Joined: Wed Nov 11, 2015 12:26 pm
Flair: Retired

Re: Need help with lua? - LunaLua General Help

Postby TDK » Mon Apr 03, 2017 12:38 pm

MosaicMario wrote:IT. NEVER. ENDS.
Now what's wrong with it?
Image

Code: Select all

local haveBoosted = false;
local haveBoostedDown = false;

function onLoop()
	if player:mem(0x146, FIELD_WORD) == 2 then
		HaveBoosted = false;
		HaveBoostedDown = false;
	end
end

function onStart()
     Level.loadPlayerHitBoxes(4, 1, "toad-1.ini")
	 Level.loadPlayerHitBoxes(4, 2, "toad-2.ini")
	 Level.loadPlayerHitBoxes(4, 3, "toad-3.ini")
	 Level.loadPlayerHitBoxes(4, 4, "toad-4.ini")
	 Level.loadPlayerHitBoxes(4, 5, "toad-5.ini")
	 Level.loadPlayerHitBoxes(4, 6, "toad-6.ini")
     Level.loadPlayerHitBoxes(4, 7, "toad-7.ini")
end

function onTick()
		if player:mem(0x146, FIELD_WORD == 0) and (player:mem(0xF4, FIELD_WORD) == true) and player.rightKeyPressing then 
		if haveBoosted == false then
		player.speedX = -5
		Audio.playSFX("dash.wav")
		do haveBoosted = true;
		end
		elseif player:mem(0x146, FIELD_WORD == 0) and (player:mem(0xF4, FIELD_WORD) == true) and player.leftKeyPressing then 
		if haveBoosted == false then
		player.speedX = 5
		Audio.playSFX("dash.wav")
		do haveBoosted = true;
		end
		elseif player:mem(0x146, FIELD_WORD == 0) and (player:mem(0xF4, FIELD_WORD) == true) and player.downKeyPressing then 
		if haveBoostedDown == false then
		player.speedY = 5
		Audio.playSFX("dash.wav")
		do haveBoostedDown = true;
		do haveBoosted = true;
						end
					end
				end
			end
		end
	end
end
There was a bracket in the wrong place in line 22, and there was a missing "end".
Last edited by TDK on Mon Apr 03, 2017 1:50 pm, edited 1 time in total.

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

Re: Need help with lua? - LunaLua General Help

Postby Emral » Mon Apr 03, 2017 1:11 pm

It won't work cause that's not how "do" works.
What are you trying to do with the "do"s? You set variables all over the place, so it can't be that.

Quantumenace
Chain Chomp
Chain Chomp
Posts: 308
Joined: Mon Dec 28, 2015 2:17 am

Re: Need help with lua? - LunaLua General Help

Postby Quantumenace » Mon Apr 03, 2017 2:56 pm

It's critical that you learn how to read error messages. It tells you what line in your lunadll.lua is causing the problem. "No matching overload" means that a function has been given the wrong types of arguments, in this case:

if player:mem(0x146, FIELD_WORD == 0)

Since you put "== 0" inside the parenthesis it takes "FIELD_WORD == 0" as a boolean, and that's an invalid argument for that function.

TheDinoKing wrote:Is there any way to make a block chase you throughout the entire level?
I tried it with chasing koopa para-troopa, but it goes off-screen and disappear.
Try setting the koopa's mem offset 0x12A to 180 or so every tick to stop it from despawning. You may also need to alter its y coordinate if it goes off the bottom of the screen and dies.

RhysOwens
Nipper
Nipper
Posts: 423
Joined: Fri Apr 22, 2016 2:53 am

Re: Need help with lua? - LunaLua General Help

Postby RhysOwens » Mon Apr 03, 2017 5:45 pm

How do you make it so LunaLua detects when you jump on a boss and it goes into it's shell form or whatever?
I also wanna know how to make it so Larry doesn't stop moving when he's firing his magic.

PersonNamedUser
Reznor
Reznor
Posts: 2882
Joined: Fri Feb 27, 2015 8:07 pm

Re: Need help with lua? - LunaLua General Help

Postby PersonNamedUser » Mon Apr 03, 2017 8:21 pm

So, after messing around a bit, i finally got the code to work probably! The only problem is that when you boost downward
the sound plays a billion times in row. Does anyone know how to fix this?
Here's the code:

Code: Select all

function onTick()
	if player:mem(0x146, FIELD_WORD) == 2 and Boosts < 1 or DownwardBoosts < 1 then
		if Boosts < 1 then Boosts = Boosts + 1;
		if DownwardBoosts < 1 then DownwardBoosts = DownwardBoosts + 1;
		end
	end
end
		if player:mem(0x146, FIELD_WORD) == 0 and player.altRunKeyPressing and player.rightKeyPressing then 
		if Boosts == 1 then
		player.speedX = 25
		Audio.playSFX("dash.wav")
		Boosts = 0;
		end
		elseif player:mem(0x146, FIELD_WORD) == 0 and player.altRunKeyPressing and player.leftKeyPressing then 
		if Boosts == 1 then
		player.speedX = -25
		Audio.playSFX("dash.wav")
		Boosts = 0;
		end
		elseif player:mem(0x146, FIELD_WORD) == 0 and player.altRunKeyPressing and player.downKeyPressing then 
		if DownwardBoosts == 1 then
		player.speedY = 25
		player.speedX = 0
		Audio.playSFX("dash.wav")
		DownwardBoosts = 0;
		Boosts = 0;
		end
	end
end

PixelPest
Link
Link
Posts: 7111
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Contact:

Re: Need help with lua? - LunaLua General Help

Postby PixelPest » Mon Apr 03, 2017 9:24 pm

RhysOwens: You can check if #NPC.get(whatever Larry's shell ID is) > 0. You'd probably have to mess with AI fields for the second one.

MosaicMario: DownwardBoosts is being switched back and forth from 0 to 1 to 0 to 1 and each time it is 1 the sound is played

PersonNamedUser
Reznor
Reznor
Posts: 2882
Joined: Fri Feb 27, 2015 8:07 pm

Re: Need help with lua? - LunaLua General Help

Postby PersonNamedUser » Tue Apr 04, 2017 3:16 am

I actually have another question, how would you make a ludwig replacement shoot projectiles faster than usual?

PixelPest
Link
Link
Posts: 7111
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Contact:

Re: Need help with lua? - LunaLua General Help

Postby PixelPest » Tue Apr 04, 2017 6:38 am

MosaicMario wrote:I actually have another question, how would you make a ludwig replacement shoot projectiles faster than usual?
Take a look at Ludwig's AI: http://wohlsoft.ru/pgewiki/SMBX_NPC_AI

RhysOwens
Nipper
Nipper
Posts: 423
Joined: Fri Apr 22, 2016 2:53 am

Re: Need help with lua? - LunaLua General Help

Postby RhysOwens » Tue Apr 04, 2017 8:06 am

PixelPest wrote:RhysOwens: You can check if #NPC.get(whatever Larry's shell ID is) > 0. You'd probably have to mess with AI fields for the second one.

MosaicMario: DownwardBoosts is being switched back and forth from 0 to 1 to 0 to 1 and each time it is 1 the sound is played
Where do I put the NPC id?

PixelPest
Link
Link
Posts: 7111
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Contact:

Re: Need help with lua? - LunaLua General Help

Postby PixelPest » Tue Apr 04, 2017 9:12 am

Between the brackets where I wrote "whatever Larry's shell ID is"

PersonNamedUser
Reznor
Reznor
Posts: 2882
Joined: Fri Feb 27, 2015 8:07 pm

Re: Need help with lua? - LunaLua General Help

Postby PersonNamedUser » Tue Apr 04, 2017 9:52 am

PixelPest wrote:
MosaicMario wrote:I actually have another question, how would you make a ludwig replacement shoot projectiles faster than usual?
Take a look at Ludwig's AI: http://wohlsoft.ru/pgewiki/SMBX_NPC_AI
thing is, i looked into it and tried putting this in:

Code: Select all

local tableOf***** = {}

function onLoop()
    tableOf***** = NPC.get(280, 16)
    for n=1, table.getn(tableOf*****) do
	    if (tableOf*****[n]:mem(0x148,FIELD_FLOAT) == 0) then
	        tableOf*****[n]:mem(0x148, FIELD_FLOAT, -2)
end
	if tableOf*****:mem(0x100, FIELD_DFLOAT) == 12 then
		tableOf*****:mem(0x100, FIELD_DFLOAT, 20)
		end
	end
end
But, all that comes up is an error message, i don't know what i'm doing wrong.

PixelPest
Link
Link
Posts: 7111
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Contact:

Re: Need help with lua? - LunaLua General Help

Postby PixelPest » Tue Apr 04, 2017 9:59 am

If you have tableOf***** actually in your file that would probably do it. Also, as I've said before, don't just say "I have an error", actually give a line number and the error message. Also table.getn is deprecated. Replace that whole function with #. Furthermore, a better way to do it is just for _, v in pairs(tableOf*****) do. Then you can use v:mem. Also, it would also error near the end where you forgot to do tableOf*****[n]:mem and just did tableOf*****:mem

RhysOwens
Nipper
Nipper
Posts: 423
Joined: Fri Apr 22, 2016 2:53 am

Re: Need help with lua? - LunaLua General Help

Postby RhysOwens » Tue Apr 04, 2017 10:39 am

I tried to make the Birdo Hit sound play when you jump on Larry and he goes into his shell form but this error shows up: ' expected near '39'.
This is the code I'm using right now.

Code: Select all

function onLoop()
     if #NPC.get(268) > 0
	     then Audio.playSFX(int 39)
	 end
end	

Quantumenace
Chain Chomp
Chain Chomp
Posts: 308
Joined: Mon Dec 28, 2015 2:17 am

Re: Need help with lua? - LunaLua General Help

Postby Quantumenace » Tue Apr 04, 2017 11:14 am

RhysOwens wrote:I tried to make the Birdo Hit sound play when you jump on Larry and he goes into his shell form but this error shows up: ' expected near '39'.
This is the code I'm using right now.

Code: Select all

function onLoop()
     if #NPC.get(268) > 0
	     then Audio.playSFX(int 39)
	 end
end	
Don't say 'int' there, just use the number.

RhysOwens
Nipper
Nipper
Posts: 423
Joined: Fri Apr 22, 2016 2:53 am

Re: Need help with lua? - LunaLua General Help

Postby RhysOwens » Tue Apr 04, 2017 12:23 pm

Quantumenace wrote:
RhysOwens wrote:I tried to make the Birdo Hit sound play when you jump on Larry and he goes into his shell form but this error shows up: ' expected near '39'.
This is the code I'm using right now.

Code: Select all

function onLoop()
     if #NPC.get(268) > 0
	     then Audio.playSFX(int 39)
	 end
end	
Don't say 'int' there, just use the number.
It's working, but how do I make it so that it only plays once?

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

Re: Need help with lua? - LunaLua General Help

Postby Emral » Tue Apr 04, 2017 12:50 pm

RhysOwens wrote:
Quantumenace wrote:
RhysOwens wrote:I tried to make the Birdo Hit sound play when you jump on Larry and he goes into his shell form but this error shows up: ' expected near '39'.
This is the code I'm using right now.

Code: Select all

function onLoop()
     if #NPC.get(268) > 0
	     then Audio.playSFX(int 39)
	 end
end	
Don't say 'int' there, just use the number.
It's working, but how do I make it so that it only plays once?
Understand your code. Also use onTick, not onLoop.
Anyway, here's your code, translated to english:

In every frame the program runs (~65 times per second) do the following:
check if there has been at least a single npc of id 268 placed down
if so, play this sound effect
repeat next frame.

Simple solution: add a check for if the sound has already played.

RhysOwens
Nipper
Nipper
Posts: 423
Joined: Fri Apr 22, 2016 2:53 am

Re: Need help with lua? - LunaLua General Help

Postby RhysOwens » Tue Apr 04, 2017 1:02 pm

Enjl wrote:In every frame the program runs (~65 times per second) do the following:
check if there has been at least a single npc of id 268 placed down
if so, play this sound effect
repeat next frame.

Simple solution: add a check for if the sound has already played.
How though? I only know the basics of LunaLua.


Return to “LunaLua”

Who is online

Users browsing this forum: No registered users and 2 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari