Need help with lua? - LunaLua General Help

This is the place for discussion and support for LunaLua and related modifications and libraries.
Forum rules
Before you make a topic/post, consider the following:
-Is there a topic for this already?
-Is your post on topic/appropriate?
-Are you posting in the right forum/following the forum rules?
Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9795
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Need help with lua? - LunaLua General Help

Postby Emral » Mon Mar 14, 2016 6:40 pm

So you're trying to get into LunaLua but
1) Don't know where to get started?
2) Have a question?

LOOK NO FURTHER THAN THIS THREAD!

How to get started
If you don't have LunaLua installed, follow these instructions:
Download the latest version of SMBX 2.0. Major updates to LunaLua and SMBX are synched.
If you want to try a laboratory build of LunaLua before the next version of SMBX, try . The Button "Download latest nightly/dev build" will provide you a download to the laboratory version of LunaLua.

If you're new to LunaLua, I suggest checking out [url=http://www.smbxgame.com/forums/v ... 87&t=12548]pyro's lua tutorials
. They're pretty outdated but still a good introduction to lua coding. Here's a few quirks you should know about, though:
-onLoop is deprecated and has been replaced with onTick
-onLoad is deprecated and has been replaced with onStart

If you're looking for documentation of any kind, you're going to find it here.

Do you have a question?

If you have a question about why your code isn't working or how to optimize something you've been working on, just reply in this thread. If you feel like your issue is major and are afraid it'll drag on over several pages or get lost, don't hesitate to make a topic about it in the forum, though.
There are many people who are experienced in lunalua (myself included) who're glad to help you out.

Just make sure that you provide enough information on your issue so we can help you. Taking a screenshot of the error message (if there is one) or posting your code using the "code" bbcode or using http://hastebin.com/ are things you should always do. If your code is long and you are getting an error, make sure to specify which lines the error is tied to (and post to hastebin rather than using the bbcode, because hastebin has line numbers). (To find which line an error appears in, look at the number at the end of the directory in the first line of the error message, or just post a picture of the error along with the code).

With that out of the way, if you have any questions regarding how to do something in lua or regarding your lua code, this is the place to go.
Last edited by Emral on Tue Jan 24, 2017 11:14 am, edited 2 times in total.

Quantix
Ripper II
Ripper II
Posts: 333
Joined: Tue Jan 26, 2016 5:04 pm

Re: Need help with lua? - LunaLua General Help

Postby Quantix » Mon Mar 14, 2016 7:05 pm

Would you happen to know to specific code for getting the player to accelerate to top speed faster?

RoundPiplup
Fuzzy
Fuzzy
Posts: 1141
Joined: Sun Jun 15, 2014 12:03 pm

Re: Need help with lua? - LunaLua General Help

Postby RoundPiplup » Mon Mar 14, 2016 7:05 pm

I need something like a step by step instructions on how to properly install/update Luna Lua on SMBX 1.3.0.1 or on SMBX 2.0. Don't know if it's just me

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9795
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Need help with lua? - LunaLua General Help

Postby Emral » Mon Mar 14, 2016 7:22 pm

RoundPiplup wrote:I need something like a step by step instructions on how to properly install/update Luna Lua on SMBX 1.3.0.1 or on SMBX 2.0. Don't know if it's just me
Right. Added to the first post.
Quantix wrote:Would you happen to know to specific code for getting the player to accelerate to top speed faster?
While I haven't seen code like that before, you should be able to use player.speedX and function onKeyDown(keyCode) to get this result. You need to watch out for edge cases though. If you're not careful, the player might be able to accelerate by holding down and right at the same time. Helpful pages for this type of code:
http://wohlsoft.ru/pgewiki/LunaLua_events
http://wohlsoft.ru/pgewiki/Player_%28class%29
http://wohlsoft.ru/pgewiki/SMBX_Player_Offsets

Alagirez
Mouser
Mouser
Posts: 3521
Joined: Tue Dec 02, 2014 2:28 am
Flair: Legalize Awooo!
Pronouns: He/Him/That wolf
Contact:

Re: Need help with lua? - LunaLua General Help

Postby Alagirez » Mon Mar 14, 2016 7:36 pm

Pls tell me how to change the character without hitting a character block with lunalua..........

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9795
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Need help with lua? - LunaLua General Help

Postby Emral » Mon Mar 14, 2016 7:45 pm

Harvey36Dice wrote:Pls tell me how to change the character without hitting a character block with lunalua..........
http://wohlsoft.ru/pgewiki/Player_%28class%29
player.character = x
where x = 1 or CHARACTER_MARIO for Mario, 2 or CHARACTER_LUIGI for Luigi, 3 or CHARACTER_PEACH for Peach, 4 or CHARACTER_TOAD for Toad, 5 or CHARACTER_LINK for Linik.
Just make sure to wrap the line above into onStart or something.

Quantix
Ripper II
Ripper II
Posts: 333
Joined: Tue Jan 26, 2016 5:04 pm

Re: Need help with lua? - LunaLua General Help

Postby Quantix » Mon Mar 14, 2016 7:45 pm

Enjl wrote:
Quantix wrote:Would you happen to know to specific code for getting the player to accelerate to top speed faster?
While I haven't seen code like that before, you should be able to use player.speedX and function onKeyDown(keyCode) to get this result. You need to watch out for edge cases though. If you're not careful, the player might be able to accelerate by holding down and right at the same time. Helpful pages for this type of code:
http://wohlsoft.ru/pgewiki/LunaLua_events
http://wohlsoft.ru/pgewiki/Player_%28class%29
http://wohlsoft.ru/pgewiki/SMBX_Player_Offsets
Well that's good enough I suppose. The player offsets thing looks intimidating, though.

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9795
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Need help with lua? - LunaLua General Help

Postby Emral » Mon Mar 14, 2016 7:50 pm

Quantix wrote:
Enjl wrote:
Quantix wrote:Would you happen to know to specific code for getting the player to accelerate to top speed faster?
While I haven't seen code like that before, you should be able to use player.speedX and function onKeyDown(keyCode) to get this result. You need to watch out for edge cases though. If you're not careful, the player might be able to accelerate by holding down and right at the same time. Helpful pages for this type of code:
http://wohlsoft.ru/pgewiki/LunaLua_events
http://wohlsoft.ru/pgewiki/Player_%28class%29
http://wohlsoft.ru/pgewiki/SMBX_Player_Offsets
Well that's good enough I suppose. The player offsets thing looks intimidating, though.
Using player offsets isn't that difficult, actually. Pyro explains it in episode 2 of her lua tutorials series, but I'll go over it real quick.
To modify offsets, you need to use
player:mem(offset, type)
to get values and
player:mem(offset, type, value)
to set values.
For example, if you want to get the player powerup (this is redundant due to player.powerup which you should use instead, but it serves as an example), you do
local variable = player:mem(0x112, FIELD_WORD)
if you want to set it to, say, mushroom, you do
player:mem(0x112, FIELD_WORD, 2)

You can use Text.print to find out proper values for different offsets.

RoundPiplup
Fuzzy
Fuzzy
Posts: 1141
Joined: Sun Jun 15, 2014 12:03 pm

Re: Need help with lua? - LunaLua General Help

Postby RoundPiplup » Mon Mar 14, 2016 7:56 pm

I got this error when I decided to do a full install on latest version.

Says "MSVCP140.dll" is missing.

Quill
Rydia
Rydia
Posts: 812
Joined: Tue Dec 03, 2013 12:51 pm
Contact:

Re: Need help with lua? - LunaLua General Help

Postby Quill » Mon Mar 14, 2016 8:06 pm

RoundPiplup wrote:I got this error when I decided to do a full install on latest version.

Says "MSVCP140.dll" is missing.
Try downloading this

RoundPiplup
Fuzzy
Fuzzy
Posts: 1141
Joined: Sun Jun 15, 2014 12:03 pm

Re: Need help with lua? - LunaLua General Help

Postby RoundPiplup » Mon Mar 14, 2016 8:24 pm

Ok I installed it. Do I have to restart the computer or is there something else I had to do after downloading and installing it?

Quantix
Ripper II
Ripper II
Posts: 333
Joined: Tue Jan 26, 2016 5:04 pm

Re: Need help with lua? - LunaLua General Help

Postby Quantix » Tue Mar 15, 2016 7:38 pm

Ok, this might be a dumb question, but you can use both LunaDll and LunaLua in the same level, right?

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9795
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Need help with lua? - LunaLua General Help

Postby Emral » Tue Mar 15, 2016 7:43 pm

Quantix wrote:Ok, this might be a dumb question, but you can use both LunaDll and LunaLua in the same level, right?
Yes.

Ness-Wednesday
Purple Yoshi Egg
Purple Yoshi Egg
Posts: 1612
Joined: Sun Jun 28, 2015 3:50 pm
Flair: Diverse Scouts
Pronouns: He/Him

Re: Need help with lua? - LunaLua General Help

Postby Ness-Wednesday » Tue Mar 15, 2016 7:53 pm

Quantix wrote:Ok, this might be a dumb question, but you can use both LunaDll and LunaLua in the same level, right?
What Enjl said.
Basically, this can go quite well if you know how to use them in a good way.
Although, I don't think there are alot of people who do this because Lunalua could do pretty much everything Lunadll can do.

HenryRichard
Birdo
Birdo
Posts: 2843
Joined: Mon Dec 23, 2013 12:09 pm
Flair: Is this where I type my password?
Contact:

Re: Need help with lua? - LunaLua General Help

Postby HenryRichard » Tue Mar 15, 2016 8:34 pm

So I'm trying to set the player's current frame using setCurrentSpriteIndex and that doesn't work at all. Any alternative suggestions?

snoruntpyro
Snifit
Snifit
Posts: 225
Joined: Sun Oct 11, 2015 9:36 am
Pronouns: she/her
Contact:

Re: Need help with lua? - LunaLua General Help

Postby snoruntpyro » Tue Mar 15, 2016 8:36 pm

HenryRichard wrote:So I'm trying to set the player's current frame using setCurrentSpriteIndex and that doesn't work at all. Any alternative suggestions?
Try using player mem value 0x114. Documentation of that is on the wiki. Also, make sure you're doing all of this in onCameraUpdate, it only works there afaik.

HenryRichard
Birdo
Birdo
Posts: 2843
Joined: Mon Dec 23, 2013 12:09 pm
Flair: Is this where I type my password?
Contact:

Re: Need help with lua? - LunaLua General Help

Postby HenryRichard » Tue Mar 15, 2016 9:10 pm

Thanks; it's working great!

EDIT: How would I make a ribbon trail with particles.lua?

Hani
Volcano Lotus
Volcano Lotus
Posts: 565
Joined: Mon Apr 13, 2015 6:34 pm

Re: Need help with lua? - LunaLua General Help

Postby Hani » Wed Mar 16, 2016 12:32 pm

I'll just ask 2 questions at a time.
Would it be possible to make an npc deadly? Like instead of just hurting you, you get instant death.
And, how do I make particles / or set up particles? Like this kind of particle.
Spoiler: show
Image
The lava specks rising into the air.
Well I hope you guys get an answer for these.. Thank you. :)

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9795
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Need help with lua? - LunaLua General Help

Postby Emral » Wed Mar 16, 2016 4:49 pm

Catastrophe wrote:I'll just ask 2 questions at a time.
Would it be possible to make an npc deadly? Like instead of just hurting you, you get instant death.
And, how do I make particles / or set up particles? Like this kind of particle.
Spoiler: show
Image
The lava specks rising into the air.
Well I hope you guys get an answer for these.. Thank you. :)
For your first question, you are able to attach a collider to an npc object and have that npc kill the player on collision. More information:
http://wohlsoft.ru/pgewiki/Colliders.lua
http://wohlsoft.ru/pgewiki/Player_%28class%29

For your second question:
http://wohlsoft.ru/pgewiki/Particles.lua
If you have this API, you can create .ini files to set rules for how your particles should move and where they should appear in their region in which they spawn, their colour, etc. It might be a bit overwhelming at first but I suggest just toying around with the contents of your ini until you have something which you're satisfied with.

Alagirez
Mouser
Mouser
Posts: 3521
Joined: Tue Dec 02, 2014 2:28 am
Flair: Legalize Awooo!
Pronouns: He/Him/That wolf
Contact:

Re: Need help with lua? - LunaLua General Help

Postby Alagirez » Thu Mar 17, 2016 1:57 am

HALPLAPLAPPALPLPLA
Pls tel me how to load an image (Image name : badge-1.png) in a level......


Return to “LunaLua”

Who is online

Users browsing this forum: No registered users and 0 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari