Page 9 of 32

Re: Need help with lua? - LunaLua General Help

Posted: Sat Nov 23, 2019 11:56 am
by SPEEDIE
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.

Re: Need help with lua? - LunaLua General Help

Posted: Sat Nov 23, 2019 1:02 pm
by Bulby_VR
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

Re: Need help with lua? - LunaLua General Help

Posted: Tue Nov 26, 2019 8:22 am
by Bulby_VR
What are the default defines for new characters? I see bowser’s jump height is much lower, but what else changes?

Re: Need help with lua? - LunaLua General Help

Posted: Sat Dec 14, 2019 5:43 pm
by MarioLover64
How do I make a fade out effect?

Re: Need help with lua? - LunaLua General Help

Posted: Sun Dec 15, 2019 1:49 am
by Emral
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}

Re: Need help with lua? - LunaLua General Help

Posted: Sun Dec 15, 2019 5:56 am
by Locus
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.

Re: Need help with lua? - LunaLua General Help

Posted: Sun Dec 15, 2019 5:58 am
by Emral
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.

Re: Need help with lua? - LunaLua General Help

Posted: Sun Dec 15, 2019 6:08 am
by Locus
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".

Re: Need help with lua? - LunaLua General Help

Posted: Sun Dec 15, 2019 6:14 am
by Emral
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.

Re: Need help with lua? - LunaLua General Help

Posted: Thu Dec 26, 2019 10:09 am
by cato
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.

Re: Need help with lua? - LunaLua General Help

Posted: Fri Dec 27, 2019 8:11 am
by RudeGuy
You need to use the SaveData library to save variables between different runs of a level.

Re: Need help with lua? - LunaLua General Help

Posted: Sat Dec 28, 2019 4:56 pm
by Murphmario
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.

Re: Need help with lua? - LunaLua General Help

Posted: Tue Jan 07, 2020 12:12 pm
by FireyPaperMario
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

Re: Need help with lua? - LunaLua General Help

Posted: Tue Jan 07, 2020 3:28 pm
by Emral
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).

Re: Need help with lua? - LunaLua General Help

Posted: Wed Jan 08, 2020 8:29 pm
by Chilly14
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

Re: Need help with lua? - LunaLua General Help

Posted: Thu Jan 09, 2020 4:10 pm
by Hoeloe
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.

Re: Need help with lua? - LunaLua General Help

Posted: Thu Jan 09, 2020 4:46 pm
by Chilly14
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?"

Re: Need help with lua? - LunaLua General Help

Posted: Fri Jan 10, 2020 2:15 am
by Hoeloe
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.

Re: Need help with lua? - LunaLua General Help

Posted: Fri Jan 10, 2020 3:05 pm
by Chilly14
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.

Re: Need help with lua? - LunaLua General Help

Posted: Sat Jan 11, 2020 3:58 pm
by Murphmario
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)."