Need help with lua? - LunaLua General Help

Post here for help and support regarding LunaLua and SMBX2's libraries and features.
User avatar
SPEEDIE
Spiny
Spiny
Posts: 43
Joined: Sat Nov 03, 2018 6:22 pm
Flair: Ninji ♥
Current Project: Bowser's Last Attempt
Chat Username: SPEEDIE
Contact:

Re: Need help with lua? - LunaLua General Help

Postby SPEEDIE » Sat Nov 23, 2019 11:56 am

I want to make a death counter on the top left part of the screen, it starts at 0, and when you die, it adds up, I want it to show in on every level (the total deaths on the entire episode)
I tried some stuff I found on pgewiki but it didn't work.
Your goals aren't always reached, that's why they are goals. :)
Image

Current Projects
Image
viewtopic.php?f=90&t=24794
Finished Projects
Image
viewtopic.php?f=36&t=23060
Please do not check this terrible piece of garbage out But you can if you want to bother me :oops:

User avatar
Bulby_VR
Koopa Troopa
Koopa Troopa
Posts: 21
Joined: Wed Aug 07, 2019 11:18 am
Current Project: Super Mario 3D World Crouch + Long Jump
Chat Username: Bulby

Re: Need help with lua? - LunaLua General Help

Postby Bulby_VR » Sat Nov 23, 2019 1:02 pm

Would changing defines on the fly negatively affect performance, or is that impossible?

Added in 1 minute 52 seconds:
Nevermind, there's no point if your thing is compatible with 2 player
an ace at making garbo code
When I use mediafire, I use adblock, and you should too when using my links.

User avatar
Bulby_VR
Koopa Troopa
Koopa Troopa
Posts: 21
Joined: Wed Aug 07, 2019 11:18 am
Current Project: Super Mario 3D World Crouch + Long Jump
Chat Username: Bulby

Re: Need help with lua? - LunaLua General Help

Postby Bulby_VR » Tue Nov 26, 2019 8:22 am

What are the default defines for new characters? I see bowser’s jump height is much lower, but what else changes?
an ace at making garbo code
When I use mediafire, I use adblock, and you should too when using my links.

User avatar
MarioLover64
Bit
Bit
Posts: 138
Joined: Fri Apr 26, 2019 6:09 pm

Re: Need help with lua? - LunaLua General Help

Postby MarioLover64 » Sat Dec 14, 2019 5:43 pm

How do I make a fade out effect?

User avatar
Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 7782
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: Need help with lua? - LunaLua General Help

Postby Enjl » Sun Dec 15, 2019 1:49 am

Bulby_VR wrote:
Tue Nov 26, 2019 8:22 am
What are the default defines for new characters? I see bowser’s jump height is much lower, but what else changes?
I don't know them off the top of my head, but each character script has an initialisation function that runs when the player turns into that character. In that function, all character-specific global fields are set.
MarioLover64 wrote:
Sat Dec 14, 2019 5:43 pm
How do I make a fade out effect?
Put this in onDraw and manually control OPACITY (from 0 to 1). Priority 5 is hud priority. https://wohlsoft.ru/pgewiki/LunaLua_Render_Priority

Graphics.drawScreen{color = Color.black .. OPACITY, priority = 5}
ImageImageImageImage
ImageImageImageImageImageImage

User avatar
Locus
Cheep-Cheep
Cheep-Cheep
Posts: 11
Joined: Sun Mar 17, 2019 12:47 pm
Flair: Dying

Re: Need help with lua? - LunaLua General Help

Postby Locus » Sun Dec 15, 2019 5:56 am

https://imgur.com/a/AuE1nko

I seem to have a problem with my parallaxing background. The water is moving but when I move left it somehow stops until I stand still again. If anyone could help me solve this issue this would be appreciated.

User avatar
Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 7782
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: Need help with lua? - LunaLua General Help

Postby Enjl » Sun Dec 15, 2019 5:58 am

Looks like an optical illusion. The water still moves at the same speed, you're just "moving it back" by moving the camera at a rate at which the parallaxing effect cancels out the movement of the water. Double the water speed to see the impact of the effect more clearly.
ImageImageImageImage
ImageImageImageImageImageImage

User avatar
Locus
Cheep-Cheep
Cheep-Cheep
Posts: 11
Joined: Sun Mar 17, 2019 12:47 pm
Flair: Dying

Re: Need help with lua? - LunaLua General Help

Postby Locus » Sun Dec 15, 2019 6:08 am

https://i.imgur.com/4bVnlKE.mp4

This time I doubled the speed and this is the result. It's like you said, making it more obvious to notice that it "stops".

User avatar
Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 7782
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: Need help with lua? - LunaLua General Help

Postby Enjl » Sun Dec 15, 2019 6:14 am

Yes, the optical illusion is more obvious here. You can greatly increase the layer's depth to reduce the impact camera movement has on the layer.
ImageImageImageImage
ImageImageImageImageImageImage

User avatar
cato
Mega Mole
Mega Mole
Posts: 288
Joined: Thu Aug 24, 2017 3:06 am
Flair: Creative, opinionated, but poor expression
Current Project: https://docs.google.com/spreadsheets/d/ ... sp=sharing
Chat Username: Cato
Contact:

Re: Need help with lua? - LunaLua General Help

Postby cato » Thu Dec 26, 2019 10:09 am

How do I print text function like the SMBX textbox, while appearing characters frame by frame?

Edit: I think I have a bigger problem.
How do I make something like:
if you play the level for the first time, it gives you text A on level start
then if you play the level after getting something, it gives you text B on level start
then if you replay the level for neither the first time nor the second time, nothing happens.

I tried:

Code: Select all

firstime = true
secondtime = false // will turn into true later
function onStart()
    if firstime == false and secondtime == false then return end
    if firstime == true then
        Text.showMessageBox("A")   
    firstime = false
    end
    if secondtime == true then 
        Text.showMessageBox("B")
        secondtime = false
    end
end   
but still can't grasp the logical error that I have since firstime is always true every time the code is executed, yet I needed something to show that it is the player's first time in the level.

User avatar
RudeGuy
Luigi
Luigi
Posts: 4977
Joined: Fri Dec 27, 2013 7:36 am
Flair: help
Current Project: a random smw hack
Chat Username: rudeguy

Re: Need help with lua? - LunaLua General Help

Postby RudeGuy » Fri Dec 27, 2019 8:11 am

You need to use the SaveData library to save variables between different runs of a level.
im bored

User avatar
Murphmario
Larry Koopa
Larry Koopa
Posts: 2018
Joined: Fri Dec 20, 2013 7:07 pm
Current Project: Project planned; waiting for SMBX2 Beta 4

Re: Need help with lua? - LunaLua General Help

Postby Murphmario » Sat Dec 28, 2019 4:56 pm

I'm trying to make an NPC that uses the AI of a Paratroopa, but I'm having two problems.

1. How do I make it face Mario without having to make it not be able to move?
2. The more major issue I'm having right now; how do I have the normal Paratroopa options show up in the editor? I copied from the Paratroopa's item code, and that didn't work.

Edit: I just decided to move onto another NPC, and now I need help with tracking the player's Y position. player.y isn't working.
Now taking graphics requests:
https://docs.google.com/forms/d/1urWpFq ... #responses

My graphics pack:
http://www.supermariobrosx.org/forums/v ... t=1960/url

Really tempted to just make a general graphics thread for all of my graphics instead of just making individual threads for each of them.

User avatar
FireyPaperMario
Peach
Peach
Posts: 5353
Joined: Sat Sep 27, 2014 1:39 pm
Flair: 90's kid born in late 1993 ^_^
Current Project: Too many things atm! Welp! :(
Chat Username: Shin FireyPaperMario
Contact:

Re: Need help with lua? - LunaLua General Help

Postby FireyPaperMario » Tue Jan 07, 2020 12:12 pm

I got this Lunalua script idea for the enemy npcs from some Japanese Super Mario Bros. 1 ROM Hack that based off the god-awful famicom Transformers game, Convoy no Nazo, where the enemies fire a small projectile at you every set of seconds. Is that possible?!?


The ROM hack is called "The Mystery of Luigi/Luigi no Nazo" if any of y'all were wondering

User avatar
Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 7782
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: Need help with lua? - LunaLua General Help

Postby Enjl » Tue Jan 07, 2020 3:28 pm

FireyPaperMario wrote:
Tue Jan 07, 2020 12:12 pm
I got this Lunalua script idea for the enemy npcs from some Japanese Super Mario Bros. 1 ROM Hack that based off the god-awful famicom Transformers game, Convoy no Nazo, where the enemies fire a small projectile at you every set of seconds. Is that possible?!?


The ROM hack is called "The Mystery of Luigi/Luigi no Nazo" if any of y'all were wondering
This thread is for people who are stuck in their code and need help in figuring out where the problem lies or how to continue. I'm willing to help once you run into such a situation, but I think the question above can be easily answered by looking at the PAL build's existing enemy roster and considering similarities between what's already been made and what you would like to make. From your description, I don't know anything about what you're actually trying to do, so please examine what already exists to determine whether the concept is possible.

(In general, pretty much anything is possible, as long as you aren't deliberately trying to break some boundary).
ImageImageImageImage
ImageImageImageImageImageImage

User avatar
Chilly14
Rex
Rex
Posts: 93
Joined: Thu Jul 18, 2019 10:28 pm
Current Project: Lots
Chat Username: Chilly Bean BAM!

Re: Need help with lua? - LunaLua General Help

Postby Chilly14 » Wed Jan 08, 2020 8:29 pm

I mostly succeeded in having a Venus Fire Trap to shoot two or more fireballs with help from 1AmPlayer. However, it doesn't work properly with multiple Venus Fire Traps onscreen:
Spoiler: show
Image
Three of the Venus Fire Traps almost constantly shoot fireballs instead of just two, while one of them briefly hides after shooting a single fireball. Plus, it's random on which one hides and which ones don't. Is there a way to fix this?
Current Code:
Spoiler: show

Code: Select all

for _,v in ipairs(NPC.get(245,player.section)) do
		local v = pnpc.wrap(v)
		local data = v.data
		
		if v.ai1 == 0 and v.ai2 == 1 then
			maxfireballs = 2
		end
		if v.ai1 == 50 and v.ai2 == 2 then
			v.ai1 = 0
			v.ai2 = 2
			maxfireballs = maxfireballs - 1
		end
		if v.ai2 == 2 and maxfireballs == 0 then
			v.ai1 = 51
			maxfireballs = -1
		end
	end
Image
For the love of god, please use an adblocker when using MediaFire to download my stuff.
My stuff:
Spoiler: show
Image
I support:
Spoiler: show
Image

User avatar
Hoeloe
Grinder
Grinder
Posts: 1098
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Current Project: A2XT Episode 2

Re: Need help with lua? - LunaLua General Help

Postby Hoeloe » Thu Jan 09, 2020 4:10 pm

The problem is that you're manipulating one variable with all your NPCs. You need to save the variables you want inside the data table you define, otherwise every NPC is going to share the same variable.

User avatar
Chilly14
Rex
Rex
Posts: 93
Joined: Thu Jul 18, 2019 10:28 pm
Current Project: Lots
Chat Username: Chilly Bean BAM!

Re: Need help with lua? - LunaLua General Help

Postby Chilly14 » Thu Jan 09, 2020 4:46 pm

Hoeloe wrote:
Thu Jan 09, 2020 4:10 pm
The problem is that you're manipulating one variable with all your NPCs. You need to save the variables you want inside the data table you define, otherwise every NPC is going to share the same variable.
Uhhh...what do you mean by "saving the variables you want inside the data table you define?"
Image
For the love of god, please use an adblocker when using MediaFire to download my stuff.
My stuff:
Spoiler: show
Image
I support:
Spoiler: show
Image

User avatar
Hoeloe
Grinder
Grinder
Posts: 1098
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Current Project: A2XT Episode 2

Re: Need help with lua? - LunaLua General Help

Postby Hoeloe » Fri Jan 10, 2020 2:15 am

Chilly14 wrote:
Thu Jan 09, 2020 4:46 pm
Hoeloe wrote:
Thu Jan 09, 2020 4:10 pm
The problem is that you're manipulating one variable with all your NPCs. You need to save the variables you want inside the data table you define, otherwise every NPC is going to share the same variable.
Uhhh...what do you mean by "saving the variables you want inside the data table you define?"

Code: Select all

local data = v.data
You make a variable called "data" here, and then never use it. This line basically just allows you to use data as a shorthand for v.data, which is the NPCs internal storage table. If you want each NPC to measure things individually, you have to store the data inside its storage table, not just floating in space.

User avatar
Chilly14
Rex
Rex
Posts: 93
Joined: Thu Jul 18, 2019 10:28 pm
Current Project: Lots
Chat Username: Chilly Bean BAM!

Re: Need help with lua? - LunaLua General Help

Postby Chilly14 » Fri Jan 10, 2020 3:05 pm

Hoeloe wrote:
Fri Jan 10, 2020 2:15 am
Chilly14 wrote:
Thu Jan 09, 2020 4:46 pm
Hoeloe wrote:
Thu Jan 09, 2020 4:10 pm
The problem is that you're manipulating one variable with all your NPCs. You need to save the variables you want inside the data table you define, otherwise every NPC is going to share the same variable.
Uhhh...what do you mean by "saving the variables you want inside the data table you define?"

Code: Select all

local data = v.data
You make a variable called "data" here, and then never use it. This line basically just allows you to use data as a shorthand for v.data, which is the NPCs internal storage table. If you want each NPC to measure things individually, you have to store the data inside its storage table, not just floating in space.
Okay, I'll try to figure it out.
Image
For the love of god, please use an adblocker when using MediaFire to download my stuff.
My stuff:
Spoiler: show
Image
I support:
Spoiler: show
Image

User avatar
Murphmario
Larry Koopa
Larry Koopa
Posts: 2018
Joined: Fri Dec 20, 2013 7:07 pm
Current Project: Project planned; waiting for SMBX2 Beta 4

Re: Need help with lua? - LunaLua General Help

Postby Murphmario » Sat Jan 11, 2020 3:58 pm

Once again having issues. Got the player.Y thing to work, but I'm getting this syntax error.
Image
Image
I tried to just change where the "end" is located, but then none of the of the code works, including the separate onNPCKill (which I referenced from Enjl's video).

Edit: I have an older NPC, and player.x = v.x doesn't seem to be working anymore. Is there a possible workaround?

Edit 2: Sorry for so many questions, but I'm now focusing on a different NPC. I'm now wondering how to fix "attempt to index local tbl (a number value)."
Now taking graphics requests:
https://docs.google.com/forms/d/1urWpFq ... #responses

My graphics pack:
http://www.supermariobrosx.org/forums/v ... t=1960/url

Really tempted to just make a general graphics thread for all of my graphics instead of just making individual threads for each of them.


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 2 guests