Page 10 of 32

Re: Need help with lua? - LunaLua General Help

Posted: Sun Jan 12, 2020 10:33 am
by Hoeloe
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.

Re: Need help with lua? - LunaLua General Help

Posted: Sun Jan 12, 2020 11:20 am
by Murphmario
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.

Re: Need help with lua? - LunaLua General Help

Posted: Sun Jan 12, 2020 11:44 am
by Emral
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.

Re: Need help with lua? - LunaLua General Help

Posted: Sun Jan 12, 2020 12:48 pm
by Murphmario
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.

Re: Need help with lua? - LunaLua General Help

Posted: Sun Jan 12, 2020 1:47 pm
by Emral
'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.

Re: Need help with lua? - LunaLua General Help

Posted: Sun Jan 12, 2020 2:00 pm
by Murphmario
Managed to fix the errors. Thanks for the help!

Re: Need help with lua? - LunaLua General Help

Posted: Wed Jan 29, 2020 11:44 am
by Chilly14
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.

Re: Need help with lua? - LunaLua General Help

Posted: Wed Feb 05, 2020 7:05 pm
by fern
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

Re: Need help with lua? - LunaLua General Help

Posted: Wed Feb 05, 2020 7:55 pm
by Sednaiur
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.

Re: Need help with lua? - LunaLua General Help

Posted: Wed Feb 05, 2020 10:37 pm
by Emral
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.

Re: Need help with lua? - LunaLua General Help

Posted: Thu Feb 06, 2020 1:27 pm
by Sednaiur
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.

Re: Need help with lua? - LunaLua General Help

Posted: Thu Feb 06, 2020 2:09 pm
by Emral
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.

Re: Need help with lua? - LunaLua General Help

Posted: Wed Feb 12, 2020 4:43 pm
by Daring Tombstone
Image

Does the altpsystem script cause this? There's no I-Frames on collecting a powerup here.

Re: Need help with lua? - LunaLua General Help

Posted: Wed Feb 12, 2020 5:58 pm
by Murphmario
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.

Re: Need help with lua? - LunaLua General Help

Posted: Fri Feb 21, 2020 6:49 pm
by Blake_Ashton_Corp
I'm trying to make a custom power up, help?

Re: Need help with lua? - LunaLua General Help

Posted: Thu Feb 27, 2020 5:38 pm
by Murphmario
How do I make an event activate after Mother Brain has been hit a few times? I can't figure it out.

Re: Need help with lua? - LunaLua General Help

Posted: Sun Mar 22, 2020 12:14 am
by LM280
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?

Re: Need help with lua? - LunaLua General Help

Posted: Sun Mar 22, 2020 4:28 am
by Emral
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

Re: Need help with lua? - LunaLua General Help

Posted: Mon Mar 23, 2020 9:20 am
by Hoeloe
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.

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

Posted: Fri Mar 27, 2020 1:03 pm
by CrazyMew37
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.)