Need help with lua? - LunaLua General Help

Post here for help and support regarding LunaLua and SMBX2's libraries and features.
User avatar
Hoeloe
Grinder
Grinder
Posts: 1019
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 » Sat May 18, 2019 8:20 pm

Enjl wrote:
Sat May 18, 2019 8:02 pm
The field doesn't work cause you set the shader and uniforms to an empty shader. The handbook details the default properties for these fields so if you don't wanna overwrite any you dont need to specify them at all.
It's as Enjl says. You should also probably just use darkness.addLight, since that will add the light to all darkness fields, and is less of a special case.

In fact, for this particular darkness field, I don't think you actually need to specify anything, since you're using entirely default values. Just darkness.create{} should do the job.

User avatar
DrMekar
Ripper II
Ripper II
Posts: 307
Joined: Sat Apr 08, 2017 7:16 am
Flair: CUSTOM CHARACTER CREATOR
Current Project: Mario Hereos 2: The Seal of Darkness, SMBXDM The Lost Levels 2, Path of Silence
Chat Username: DrMekar
Contact:

Re: Need help with lua? - LunaLua General Help

Postby DrMekar » Sun May 19, 2019 9:57 am

Enjl wrote:
Sat May 18, 2019 8:02 pm
darknessField is a variable which you can name anything, though if you're familiar with programming I would avoid reserved symbols like ,.-+*/%"' etc...

The field doesn't work cause you set the shader and uniforms to an empty shader. The handbook details the default properties for these fields so if you don't wanna overwrite any you dont need to specify them at all.
okay, so that makes alot of sense xD. But where do I put the missing comma, if not behind nil or true
My Youtube Channel: https://www.youtube.com/channel/UC-8fzX ... subscriber

Current Project: Mario Heroes 2: The Seal of Darkness
posting.php?mode=edit&f=90&t=23148&p=339823#previewImage

Last Project: Mario Heroes: The First Chapter

Great Folks who support/ed my projects/in the past:

Suecra
jaf
Suckerman7 HM

User avatar
Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 7481
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 May 19, 2019 10:01 am

DrMekar wrote:
Sun May 19, 2019 9:57 am
Enjl wrote:
Sat May 18, 2019 8:02 pm
darknessField is a variable which you can name anything, though if you're familiar with programming I would avoid reserved symbols like ,.-+*/%"' etc...

The field doesn't work cause you set the shader and uniforms to an empty shader. The handbook details the default properties for these fields so if you don't wanna overwrite any you dont need to specify them at all.
okay, so that makes alot of sense xD. But where do I put the missing comma, if not behind nil or true
The error message told you that it expected the declaration to end where it found "boundLength", so perhaps after the previous argument? Though you r eally don't have to specify either of these in the first place, so by cleaning up your code the error will just go away.
ImageImageImageImage
ImageImageImageImageImageImage

User avatar
DrMekar
Ripper II
Ripper II
Posts: 307
Joined: Sat Apr 08, 2017 7:16 am
Flair: CUSTOM CHARACTER CREATOR
Current Project: Mario Hereos 2: The Seal of Darkness, SMBXDM The Lost Levels 2, Path of Silence
Chat Username: DrMekar
Contact:

Re: Need help with lua? - LunaLua General Help

Postby DrMekar » Sun May 19, 2019 10:20 am

Enjl wrote:
Sun May 19, 2019 10:01 am
DrMekar wrote:
Sun May 19, 2019 9:57 am
Enjl wrote:
Sat May 18, 2019 8:02 pm
darknessField is a variable which you can name anything, though if you're familiar with programming I would avoid reserved symbols like ,.-+*/%"' etc...

The field doesn't work cause you set the shader and uniforms to an empty shader. The handbook details the default properties for these fields so if you don't wanna overwrite any you dont need to specify them at all.
okay, so that makes alot of sense xD. But where do I put the missing comma, if not behind nil or true
The error message told you that it expected the declaration to end where it found "boundLength", so perhaps after the previous argument? Though you r eally don't have to specify either of these in the first place, so by cleaning up your code the error will just go away.
Image
Still the same message :(
My Youtube Channel: https://www.youtube.com/channel/UC-8fzX ... subscriber

Current Project: Mario Heroes 2: The Seal of Darkness
posting.php?mode=edit&f=90&t=23148&p=339823#previewImage

Last Project: Mario Heroes: The First Chapter

Great Folks who support/ed my projects/in the past:

Suecra
jaf
Suckerman7 HM

User avatar
Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 7481
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 May 19, 2019 10:39 am

You haven't really taken any of hoeloe and I's advice either, so no surprise there.


The field doesn't work cause you set the shader and uniforms to an empty shader. The handbook details the default properties for these fields so if you don't wanna overwrite any you dont need to specify them at all.

You should also probably just use darkness.addLight, since that will add the light to all darkness fields, and is less of a special case.

In fact, for this particular darkness field, I don't think you actually need to specify anything, since you're using entirely default values. Just darkness.create{} should do the job.
ImageImageImageImage
ImageImageImageImageImageImage

User avatar
DrMekar
Ripper II
Ripper II
Posts: 307
Joined: Sat Apr 08, 2017 7:16 am
Flair: CUSTOM CHARACTER CREATOR
Current Project: Mario Hereos 2: The Seal of Darkness, SMBXDM The Lost Levels 2, Path of Silence
Chat Username: DrMekar
Contact:

Re: Need help with lua? - LunaLua General Help

Postby DrMekar » Sun May 19, 2019 10:50 am

Enjl wrote:
Sun May 19, 2019 10:39 am
You haven't really taken any of hoeloe and I's advice either, so no surprise there.


The field doesn't work cause you set the shader and uniforms to an empty shader. The handbook details the default properties for these fields so if you don't wanna overwrite any you dont need to specify them at all.

You should also probably just use darkness.addLight, since that will add the light to all darkness fields, and is less of a special case.

In fact, for this particular darkness field, I don't think you actually need to specify anything, since you're using entirely default values. Just darkness.create{} should do the job.
Well, Now it works. I'm not entirely sure what advises you mean thougth.
Thanks never the less

Added in 1 hour 50 minutes 37 seconds:
I hate to ask again, but this time it isen't a stupid question I hope ;)
I want to attach the Red Light to Cleeyores (The Flying Grey Boss NPC). I used the BG Mechanic you showed in the tutrorial and it worked fine, but
obviously only at her spawn point, so I wondered if it is possible to make the light follow her.
Image
This is how the lua looks currently if necessary.
Image
My Youtube Channel: https://www.youtube.com/channel/UC-8fzX ... subscriber

Current Project: Mario Heroes 2: The Seal of Darkness
posting.php?mode=edit&f=90&t=23148&p=339823#previewImage

Last Project: Mario Heroes: The First Chapter

Great Folks who support/ed my projects/in the past:

Suecra
jaf
Suckerman7 HM

Draex
Shy Guy
Shy Guy
Posts: 5
Joined: Thu May 16, 2019 11:34 pm
Flair: Flair Text
Chat Username: Draex

Re: Need help with lua? - LunaLua General Help

Postby Draex » Sun May 19, 2019 5:51 pm

What would I use if I want the platform to change color when simply touched by the player, instead of just when stood on?

User avatar
Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 7481
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 May 19, 2019 6:19 pm

DrMekar wrote:
Sun May 19, 2019 12:40 pm
https://docs.google.com/spreadsheets/d/ ... edit#gid=0
Draex wrote:
Sun May 19, 2019 5:51 pm
What would I use if I want the platform to change color when simply touched by the player, instead of just when stood on?
Set a variable on the NPC when the NPC is first touched.

Load pnpc, check if player.standingNPC exists and is of the correct ID, and then
local touchedNPC = pnpc.wrap(player.standingNPC)
touchedNPC.data.touched = true

Then you can use a for loop over NPCs of that ID in onDraw, wrap them again, and change their rendered frame by setting its animationFrame
ImageImageImageImage
ImageImageImageImageImageImage

User avatar
DrMekar
Ripper II
Ripper II
Posts: 307
Joined: Sat Apr 08, 2017 7:16 am
Flair: CUSTOM CHARACTER CREATOR
Current Project: Mario Hereos 2: The Seal of Darkness, SMBXDM The Lost Levels 2, Path of Silence
Chat Username: DrMekar
Contact:

Re: Need help with lua? - LunaLua General Help

Postby DrMekar » Mon May 20, 2019 1:33 am

Enjl wrote:
Sun May 19, 2019 6:19 pm
DrMekar wrote:
Sun May 19, 2019 12:40 pm
https://docs.google.com/spreadsheets/d/ ... edit#gid=0
Draex wrote:
Sun May 19, 2019 5:51 pm
What would I use if I want the platform to change color when simply touched by the player, instead of just when stood on?
Set a variable on the NPC when the NPC is first touched.

Load pnpc, check if player.standingNPC exists and is of the correct ID, and then
local touchedNPC = pnpc.wrap(player.standingNPC)
touchedNPC.data.touched = true

Then you can use a for loop over NPCs of that ID in onDraw, wrap them again, and change their rendered frame by setting its animationFrame
Okay, Thanks
My Youtube Channel: https://www.youtube.com/channel/UC-8fzX ... subscriber

Current Project: Mario Heroes 2: The Seal of Darkness
posting.php?mode=edit&f=90&t=23148&p=339823#previewImage

Last Project: Mario Heroes: The First Chapter

Great Folks who support/ed my projects/in the past:

Suecra
jaf
Suckerman7 HM

User avatar
Hoeloe
Grinder
Grinder
Posts: 1019
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 May 20, 2019 7:57 am

DrMekar wrote:
Sun May 19, 2019 12:40 pm
I used the BG Mechanic you showed in the tutrorial and it worked fine, but
obviously only at her spawn point, so I wondered if it is possible to make the light follow her.
Image
This is how the lua looks currently if necessary.
Image
Well, you never actually told the light to follow anything, you just put it at the same location as the npc.

Really, if you want an npc to have a light on it, you should use npc.txt files rather than lua. You can just add:

Code: Select all

lightbrightness=1
lightcolor=red
lightradius=128
To the npc.txt for your npc, and that will automatically give it a light.

FluffyMeatloaf
Goomba
Goomba
Posts: 2
Joined: Mon May 20, 2019 10:19 am
Flair: ruh roh
Chat Username: FluffLoaf

Re: Need help with lua? - LunaLua General Help

Postby FluffyMeatloaf » Mon May 20, 2019 10:42 am

Soooo I haven't dabbled in lua before. Heard a bunch about it, saw some neat stuff in a previous contest... and in light of recent going-ons I was curious if lua could do a thing, that thing being modifications to the music packaged with the engine?

Now I watched Enjl's tutorial on music related bits and that's pretty handy for doing the intros and loops, but I'm thinking of something that just the lua would do, if possible. Things like raising pitch, slowing tempo, playing backwards, that kinda thing? I think my main thought behind this is a way to save on file size, because instead of adding custom tunes one could just rework what's already there to have something that sounds different? Sorta like what they did with Pokemon cries in the first Pokemon games... though that might be a poor example for something based on Mario.

Apologies if any of that's hard to follow, or sounds rude. I meant to bring up something like this for a bit now and just kinda... lost track of time. Argh.

User avatar
DrMekar
Ripper II
Ripper II
Posts: 307
Joined: Sat Apr 08, 2017 7:16 am
Flair: CUSTOM CHARACTER CREATOR
Current Project: Mario Hereos 2: The Seal of Darkness, SMBXDM The Lost Levels 2, Path of Silence
Chat Username: DrMekar
Contact:

Re: Need help with lua? - LunaLua General Help

Postby DrMekar » Mon May 20, 2019 10:58 am

Hoeloe wrote:
Mon May 20, 2019 7:57 am
DrMekar wrote:
Sun May 19, 2019 12:40 pm
I used the BG Mechanic you showed in the tutrorial and it worked fine, but
obviously only at her spawn point, so I wondered if it is possible to make the light follow her.
Image
This is how the lua looks currently if necessary.
Image
Well, you never actually told the light to follow anything, you just put it at the same location as the npc.

Really, if you want an npc to have a light on it, you should use npc.txt files rather than lua. You can just add:

Code: Select all

lightbrightness=1
lightcolor=red
lightradius=128
To the npc.txt for your npc, and that will automatically give it a light.
Well that's really nice to know. I'll defenitly give my Custom a Green Light with this too. Thanks again :)
My Youtube Channel: https://www.youtube.com/channel/UC-8fzX ... subscriber

Current Project: Mario Heroes 2: The Seal of Darkness
posting.php?mode=edit&f=90&t=23148&p=339823#previewImage

Last Project: Mario Heroes: The First Chapter

Great Folks who support/ed my projects/in the past:

Suecra
jaf
Suckerman7 HM

User avatar
Hoeloe
Grinder
Grinder
Posts: 1019
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 May 20, 2019 12:41 pm

FluffyMeatloaf wrote:
Mon May 20, 2019 10:42 am
Soooo I haven't dabbled in lua before. Heard a bunch about it, saw some neat stuff in a previous contest... and in light of recent going-ons I was curious if lua could do a thing, that thing being modifications to the music packaged with the engine?

Now I watched Enjl's tutorial on music related bits and that's pretty handy for doing the intros and loops, but I'm thinking of something that just the lua would do, if possible. Things like raising pitch, slowing tempo, playing backwards, that kinda thing? I think my main thought behind this is a way to save on file size, because instead of adding custom tunes one could just rework what's already there to have something that sounds different? Sorta like what they did with Pokemon cries in the first Pokemon games... though that might be a poor example for something based on Mario.

Apologies if any of that's hard to follow, or sounds rude. I meant to bring up something like this for a bit now and just kinda... lost track of time. Argh.
Sadly, one of the biggest limitations of SMBX at the moment is its audio engine. We don't currently have a way to modify the pitch or tempo of music tracks, or play multiple tracks at once.

Added in 1 minute 9 seconds:
DrMekar wrote:
Mon May 20, 2019 10:58 am
Well that's really nice to know. I'll defenitly give my Custom a Green Light with this too. Thanks again :)

Also, I did mention you should use
darkness.addLight
rather than
darknessField:addLight
It won't make much of a difference in the current setup, but it's generally better practice.

User avatar
DrMekar
Ripper II
Ripper II
Posts: 307
Joined: Sat Apr 08, 2017 7:16 am
Flair: CUSTOM CHARACTER CREATOR
Current Project: Mario Hereos 2: The Seal of Darkness, SMBXDM The Lost Levels 2, Path of Silence
Chat Username: DrMekar
Contact:

Re: Need help with lua? - LunaLua General Help

Postby DrMekar » Mon May 20, 2019 12:52 pm

Hoeloe wrote:
Mon May 20, 2019 12:43 pm
FluffyMeatloaf wrote:
Mon May 20, 2019 10:42 am
Soooo I haven't dabbled in lua before. Heard a bunch about it, saw some neat stuff in a previous contest... and in light of recent going-ons I was curious if lua could do a thing, that thing being modifications to the music packaged with the engine?

Now I watched Enjl's tutorial on music related bits and that's pretty handy for doing the intros and loops, but I'm thinking of something that just the lua would do, if possible. Things like raising pitch, slowing tempo, playing backwards, that kinda thing? I think my main thought behind this is a way to save on file size, because instead of adding custom tunes one could just rework what's already there to have something that sounds different? Sorta like what they did with Pokemon cries in the first Pokemon games... though that might be a poor example for something based on Mario.

Apologies if any of that's hard to follow, or sounds rude. I meant to bring up something like this for a bit now and just kinda... lost track of time. Argh.
Sadly, one of the biggest limitations of SMBX at the moment is its audio engine. We don't currently have a way to modify the pitch or tempo of music tracks, or play multiple tracks at once.

Added in 1 minute 9 seconds:
DrMekar wrote:
Mon May 20, 2019 10:58 am
Well that's really nice to know. I'll defenitly give my Custom a Green Light with this too. Thanks again :)

Also, I did mention you should use
darkness.addLight
rather than
darknessField:addLight
It won't make much of a difference in the current setup, but it's generally better practice.
Will do that if needed :)
My Youtube Channel: https://www.youtube.com/channel/UC-8fzX ... subscriber

Current Project: Mario Heroes 2: The Seal of Darkness
posting.php?mode=edit&f=90&t=23148&p=339823#previewImage

Last Project: Mario Heroes: The First Chapter

Great Folks who support/ed my projects/in the past:

Suecra
jaf
Suckerman7 HM

FluffyMeatloaf
Goomba
Goomba
Posts: 2
Joined: Mon May 20, 2019 10:19 am
Flair: ruh roh
Chat Username: FluffLoaf

Re: Need help with lua? - LunaLua General Help

Postby FluffyMeatloaf » Mon May 20, 2019 2:41 pm

Hoeloe wrote:
Mon May 20, 2019 12:43 pm
Sadly, one of the biggest limitations of SMBX at the moment is its audio engine. We don't currently have a way to modify the pitch or tempo of music tracks, or play multiple tracks at once.
Well, farts. Glad I asked, though. Thanks for letting me know!

User avatar
masonman1118
Spiny
Spiny
Posts: 45
Joined: Fri Jul 25, 2014 9:47 pm
Current Project: Luigi's Exclusive Expedition

Re: Need help with lua? - LunaLua General Help

Postby masonman1118 » Wed May 22, 2019 7:08 pm

Hello. I am not sure if this is allowed in this thread, but I was just wondering if there was currently any .lua for a dragon coin counter on the HUD? I couldn't seem to find one myself, but I may be missing something.

If not, I may just learn LunaLua and figure it all out on my own.

Thanks for any help!
I make world maps! PM me if interested!

My Project!

Image

User avatar
Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 7481
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 May 22, 2019 7:15 pm

A similar feature is programmed in this episode of lua tutorials.
https://www.youtube.com/watch?v=7QLdRTkpTrQ
It can be easily adapted to an onscreen counter.
ImageImageImageImage
ImageImageImageImageImageImage

Draex
Shy Guy
Shy Guy
Posts: 5
Joined: Thu May 16, 2019 11:34 pm
Flair: Flair Text
Chat Username: Draex

Re: Need help with lua? - LunaLua General Help

Postby Draex » Fri May 24, 2019 1:52 am

Enjl wrote:
Sun May 19, 2019 6:19 pm
Draex wrote:
Sun May 19, 2019 5:51 pm
What would I use if I want the platform to change color when simply touched by the player, instead of just when stood on?
Set a variable on the NPC when the NPC is first touched.

Load pnpc, check if player.standingNPC exists and is of the correct ID, and then
local touchedNPC = pnpc.wrap(player.standingNPC)
touchedNPC.data.touched = true

Then you can use a for loop over NPCs of that ID in onDraw, wrap them again, and change their rendered frame by setting its animationFrame
I looked through the docs but I'm not sure I'm clear on how to set animation frames.

Here's what I have so far. It's my lunadll file. https://paste.mod.gg/olegifaroh.rb Due to some complications I'm having with the computer I'm using right now I am incapable of testing that code to see if it works or not, but does it look to be on the right track?

Draex
Shy Guy
Shy Guy
Posts: 5
Joined: Thu May 16, 2019 11:34 pm
Flair: Flair Text
Chat Username: Draex

Re: Need help with lua? - LunaLua General Help

Postby Draex » Sat May 25, 2019 11:09 am

Actually I'm not sure I was quite clear enough when I said I wanted the platform to change color when touched by the player. I don't just mean when stood on, I mean when touched from any side, like below, for instance.

User avatar
Quantumenace
Mega Mole
Mega Mole
Posts: 291
Joined: Mon Dec 28, 2015 2:17 am

Re: Need help with lua? - LunaLua General Help

Postby Quantumenace » Sun May 26, 2019 5:28 pm

I'm trying to load a lua file from the luna.lua file like it is the actual luna.lua file. require() loads it but the events don't get registered. This looks like it works:

Code: Select all

for i,v in pairs(Misc.LUNALUA_EVENTS) do EventManager.userListeners[1][v]=_G[v] end
but I think that would replace the events in the luaworld file or whatever. I'd try to use _ENV[v]=_G[v] but _ENV returns nil. Any ideas?


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 24 guests