Need help with lua? - LunaLua General Help

Post here for help and support regarding LunaLua and SMBX2's libraries and features.
User avatar
Hoeloe
Kamikaze Koopa
Kamikaze Koopa
Posts: 1204
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 » Sun Jan 12, 2020 10:33 am

That depends on what your code is. We aren't psychic, we can't fix your code errors without looking at it.

That said, the first error message you posted means you put an "else" to try and close off a function. The "else" keyword is only valid for conditional statements, so it errored.

The second error means you have an object called "tbl" which you are trying to index (i.e. do something like "tbl.myField" or "tbl[myIndex]"). The problem is that "tbl" is a number, and indexing means to look at a subfield stored in that object. Numbers cannot have subfields, only tables can, so it errors.

User avatar
Murphmario
Larry Koopa
Larry Koopa
Posts: 2136
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 » Sun Jan 12, 2020 11:20 am

OK to the code thing. As for the second error, I'm not even trying to index an object called "tbl". I'm trying to have a local variable that's set to 1 once Mario stands on the NPC, then gets off it. Whenever Mario jumps off the NPC, the error occurs.
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.

Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 8422
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 Jan 12, 2020 11:44 am

Two things would be incredibly helpful.
1) The ACTUAL error message. Usually errors come with line numbers where the error happened, as well as a stacktrace that lets you trace back where the code was even executed from. https://cdn.discordapp.com/attachments/ ... nknown.png
2) The code. http://hastebin.com/ works well as a dumping ground for code that expires after a few weeks.
The ABC of Creation
________________________________________________________
Image

User avatar
Murphmario
Larry Koopa
Larry Koopa
Posts: 2136
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 » Sun Jan 12, 2020 12:48 pm

Okay. Might as well.
The code (it's four NPCs that function the same since I'm not really that good at making an AI file. Also can't figure out how to save with Hastebin, so I'm just going to share the file itself): https://www.dropbox.com/s/pgzgiemsld54e ... 1.lua?dl=0
And the error message:
Image

Edit: Should note that I copied some code from one of Enjl's platforms since I couldn't figure out how to make the player standing function myself. Credit will be properly given when/if the NPC is released.
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.

Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 8422
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 Jan 12, 2020 1:47 pm

'kay let's see...

Stacktrace says the error is in line 128. Dropbox must've inserted some lines. Since the stacktrace thinks line 94 is where onTickNPC begins, that means line 126 is the error.
v.pressed = 1

I suspect the error is that NPCs don't have a "pressed" field, and thus assigning it makes no sense. Did you mean to assign to data.pressed?

E: Actually I got the line wrong. While I suspect that line to cause errors, the real mistake is in line 130 and is because you have a period between v and transform intead of a colon.
v:transform(id) is functionally identical to v.transform(v, id). So if you do v.transform(id) it fails to index the id as a npc object.
The ABC of Creation
________________________________________________________
Image

User avatar
Murphmario
Larry Koopa
Larry Koopa
Posts: 2136
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 » Sun Jan 12, 2020 2:00 pm

Managed to fix the errors. Thanks for the help!
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
Chilly14
Bit
Bit
Posts: 131
Joined: Thu Jul 18, 2019 10:28 pm
Flair: wash your hands and stay at home
Current Project: Lots

Re: Need help with lua? - LunaLua General Help

Postby Chilly14 » Wed Jan 29, 2020 11:44 am

Is there a way I can modify a Venus Fire Trap's attack depending on the layer the NPC's part of? I mean, I'm trying to get VFTs to behave as normal in the "Default" layer, while VFTs in a "Gunner" layer to shoot multiple fireballs.
Discord username: Chilly Bean BAM!#8857
Image
For the love of god, please use an adblocker (I prefer uBlock Origin) when using MediaFire to download my stuff.
Check out my levels!
Chilly14's Graphics Pack
Chilly's NPCs
screenRotate.lua
venusFireTrapPlus.lua
I support:
Spoiler: show
Image
Image

User avatar
fern
Spiny
Spiny
Posts: 56
Joined: Sat Dec 02, 2017 8:59 pm
Chat Username: fern

Re: Need help with lua? - LunaLua General Help

Postby fern » Wed Feb 05, 2020 7:05 pm

Is there something I'm missing here? Trying to play a sound file from an npc.lua file like this: SFX.play("sound/spike.wav")

I've tried without specifying the file path, as well as moving the sound file out into the episode folder to no avail. The only way I can play sounds is by replacing them through sounds.ini and playing the SFX ID.
In the tester, I just get a warning saying the file could not be loaded, and the following error once I exit.
Spoiler: show
Image

User avatar
Sednaiur
Volcano Lotus
Volcano Lotus
Posts: 561
Joined: Fri Dec 20, 2013 2:16 pm
Current Project: Lowser's Conquest "Relowserd"

Re: Need help with lua? - LunaLua General Help

Postby Sednaiur » Wed Feb 05, 2020 7:55 pm

I like to ask for assistance on how to add a custom color switch including the switch palace for the world map.
Adding them in the editor is no problem, but getting it to work in the level is not as simple as anticipated. I asked the Google document about it but the article did not well in explaining it understandable for me.

These are the elements I have in the folder of my test level:
Image

And when I test the level, this is what pops up before the level is fully loaded:
Image

Then, this message pops up, before the level is started:
Image
I edited all the numbers accordingly and added the custom IDs too.
I couldn't find any .lua files for the toggled switch blocks as a reference (ex. block 724 to 731), though.

Would someone like to explain to me how this works?
Thanks for any help provided.

Image

愛している、ビアンカ!

Lua-rank:Image

Spoiler: show

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

Re: Need help with lua? - LunaLua General Help

Postby Enjl » Wed Feb 05, 2020 10:37 pm

Sednaiur wrote:
Wed Feb 05, 2020 7:55 pm
The line in question is this:
bigSwitch.charms[customSettings.color] = resolveParticleFile(customSettings.color)

It's looking for the burst particles in the subfolder particles/switch/part_ ... .png
local function resolveParticleFile(filename)
filename = "switch/part_"..filename..".png"
local a = Misc.multiResolveFile(filename, "particles/"..filename, "graphics/particles/"..filename)
return Graphics.loadImage(a)
end

where ... is the name of the colour.

Toggled switch blocks are unaware of all that's happening to them. It's handled through the switch color you define. See the blockon and blockoff values of npc-441.lua for reference.
The ABC of Creation
________________________________________________________
Image

User avatar
Sednaiur
Volcano Lotus
Volcano Lotus
Posts: 561
Joined: Fri Dec 20, 2013 2:16 pm
Current Project: Lowser's Conquest "Relowserd"

Re: Need help with lua? - LunaLua General Help

Postby Sednaiur » Thu Feb 06, 2020 1:27 pm

Enjl wrote:
Wed Feb 05, 2020 10:37 pm
Thank you very much for your help. The problem is solved and the new switch color now works in the level without errors.
I still need to test it on the world map, but hopefully everything will be fine.

Also interesting is how the big color switch gets unpressed and usable again, as soon as the toggle color switch block is hit. I am very happy and grateful about all the new tools and toys we got.

Image

愛している、ビアンカ!

Lua-rank:Image

Spoiler: show

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

Re: Need help with lua? - LunaLua General Help

Postby Enjl » Thu Feb 06, 2020 2:09 pm

Sednaiur wrote:
Thu Feb 06, 2020 1:27 pm
Enjl wrote:
Wed Feb 05, 2020 10:37 pm
Also interesting is how the big color switch gets unpressed and usable again, as soon as the toggle color switch block is hit. I am very happy and grateful about all the new tools and toys we got.
Glad that resolved it!
About the toggle blocks: They're basically a secondary way to use the switches. Either as SMW-style palace-switches, or as persistent-cross-level-state switches. The big buttons help episodes that like to do the former, the switches help with the latter. Of course nothing stops you from dedicating certain colours to either of those functions.
The ABC of Creation
________________________________________________________
Image

User avatar
Daring Tombstone
Bit
Bit
Posts: 142
Joined: Mon Aug 28, 2017 10:57 pm
Flair: What? Not 1000 posts? That means I suck right?
Current Project: Something Maybe
Chat Username: Chaperone

Re: Need help with lua? - LunaLua General Help

Postby Daring Tombstone » Wed Feb 12, 2020 4:43 pm

Image

Does the altpsystem script cause this? There's no I-Frames on collecting a powerup here.
Last edited by Daring Tombstone on Wed Feb 12, 2020 7:06 pm, edited 1 time in total.
Happy Dance
Image
Check out my completed episode
Spoiler: show
Image
Check out my halloween level
Spoiler: show
Image

User avatar
Murphmario
Larry Koopa
Larry Koopa
Posts: 2136
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 » Wed Feb 12, 2020 5:58 pm

Two simple questions:
-How do I make it so that a block doesn't change to the SMB3 used block when it's contents are released?
-How would I add momentum to the player? SpeedX doesn't really work since holding the run button cancels the momentum from what I'm trying to use.
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.

Blake_Ashton_Corp
Goomba
Goomba
Posts: 2
Joined: Sat Jan 18, 2020 5:05 pm
Current Project: Super Mario Adventures
Chat Username: Your Lord Blake

Re: Need help with lua? - LunaLua General Help

Postby Blake_Ashton_Corp » Fri Feb 21, 2020 6:49 pm

I'm trying to make a custom power up, help?

User avatar
Murphmario
Larry Koopa
Larry Koopa
Posts: 2136
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 » Thu Feb 27, 2020 5:38 pm

How do I make an event activate after Mother Brain has been hit a few times? I can't figure it out.
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
LM280
Swooper
Swooper
Posts: 122
Joined: Wed Jan 15, 2014 7:10 pm
Current Project: Super Mario-Troid

Re: Need help with lua? - LunaLua General Help

Postby LM280 » Sun Mar 22, 2020 12:14 am

Is there a way to check if the player is on the ground that still works if the player is standing on a slope or a standable NPC?

Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 8422
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 Mar 22, 2020 4:28 am

Oh whoops, seems like I haven't visited this thread in a while.
Daring Tombstone wrote:
Wed Feb 12, 2020 4:43 pm
Does the altpsystem script cause this? There's no I-Frames on collecting a powerup here.
Could be the case. I don't know the file well enough, but you could try to take a look at any instances of manipulating offset 0x140 in the player struct.
Murphmario wrote:
Wed Feb 12, 2020 5:58 pm
Two simple questions:
-How do I make it so that a block doesn't change to the SMB3 used block when it's contents are released?
-How would I add momentum to the player? SpeedX doesn't really work since holding the run button cancels the momentum from what I'm trying to use.
1. Could try to make an event onPostBlockHit(block) and set the ID there. We don't have the field exposed natively. If that doesn't work, you can use onBlockHit(eventObj, block) and cancel the eventObj and handle the hit yourself using functions in blockutils.lua. The reserve item powerup box does something like this and you could use it for reference.
2. If you want to go over the speed cap, you need to manipulate Defines.player_runspeed for the duration of your high speed event to prevent the player from activating the run cap. Remember to reset it to its initial value when the high speed event is done.
Blake_Ashton_Corp wrote:
Fri Feb 21, 2020 6:49 pm
I'm trying to make a custom power up, help?
This is very complicated. Chances are if you haven't written any simpler lua scripts since posting this question, you won't be able to make sense of the advice I could give on this. Step 1: Get familiar with lua and lunalua: https://wohlsoft.ru/pgewiki/Category:LunaLua_API
Murphmario wrote:
Thu Feb 27, 2020 5:38 pm
How do I make an event activate after Mother Brain has been hit a few times? I can't figure it out.
Print the value of offset 0x148 for the NPC to the screen. Its value will tell you what you need to do. https://wohlsoft.ru/pgewiki/NPC_(class)#Offsets
LM280 wrote:
Sun Mar 22, 2020 12:14 am
Is there a way to check if the player is on the ground that still works if the player is standing on a slope or a standable NPC?
if player:isGroundTouching() then
The ABC of Creation
________________________________________________________
Image

User avatar
Hoeloe
Kamikaze Koopa
Kamikaze Koopa
Posts: 1204
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 » Mon Mar 23, 2020 9:20 am

Enjl wrote:
Sun Mar 22, 2020 4:28 am

if player:isGroundTouching() then
if player:isOnGround() then

is the more modern approach - they do the same thing, but the latter one is shorter.

User avatar
CrazyMew37
Goomba
Goomba
Posts: 1
Joined: Mon Jan 15, 2018 3:06 pm
Flair: Hello and Goodbye!
Current Project: AMSEBIHKAJATWM
Chat Username: Berry the Mew

Re: Need help with lua? - LunaLua General Help (Lighting Effects)

Postby CrazyMew37 » Fri Mar 27, 2020 1:03 pm

Hello! I want to create a stage effect in one of the sections of my stage where the lighting of the level goes down and then goes up again in a repeating manner. Perhaps this could be for both the backgrounds, blocks, and NPCs (If Possible), to make it a bit of a challenge. The Speed of the Light fading away and fading back should be quick, but not too quick. How could I possibly do this? (Also, this is just for one entire section of the level. Not the whole thing or a part of a section.)
Last edited by CrazyMew37 on Fri Mar 27, 2020 4:45 pm, edited 1 time in total.
REMEMBER KIDS: Make sure to ask your parents before pirating DPPt!!!


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 1 guest