Need help with lua? - LunaLua General Help

This is the place for discussion and support for LunaLua and related modifications and libraries.

Moderator: Userbase Moderators

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?
cato
Volcano Lotus
Volcano Lotus
Posts: 559
Joined: Thu Aug 24, 2017 3:06 am
Flair: Koishi enjoyer
Contact:

Re: Need help with lua? - LunaLua General Help

Postby cato » Sat May 26, 2018 8:13 am

How to make autoscroll in other sections ? If possible......

Novarender
Tweeter
Tweeter
Posts: 145
Joined: Sat Aug 06, 2016 6:59 pm
Flair: Whoa

Re: Need help with lua? - LunaLua General Help

Postby Novarender » Sun May 27, 2018 3:19 pm

How can you determine the distance between the player and the nearest block underneath them? Or at least detect if they are in mid-air?

PixelPest
Link
Link
Posts: 7111
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Contact:

Re: Need help with lua? - LunaLua General Help

Postby PixelPest » Sun May 27, 2018 3:25 pm

Notxarb wrote:
Sun May 27, 2018 3:19 pm
How can you determine the distance between the player and the nearest block underneath them? Or at least detect if they are in mid-air?
You can check:

Code: Select all

not player:isGroundTouching()

Novarender
Tweeter
Tweeter
Posts: 145
Joined: Sat Aug 06, 2016 6:59 pm
Flair: Whoa

Re: Need help with lua? - LunaLua General Help

Postby Novarender » Sun May 27, 2018 3:37 pm

PixelPest wrote:
Sun May 27, 2018 3:25 pm
Notxarb wrote:
Sun May 27, 2018 3:19 pm
How can you determine the distance between the player and the nearest block underneath them? Or at least detect if they are in mid-air?
You can check:

Code: Select all

not player:isGroundTouching()
Specifically what does this represent? (Slopes? NPCs?)

PixelPest
Link
Link
Posts: 7111
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Contact:

Re: Need help with lua? - LunaLua General Help

Postby PixelPest » Sun May 27, 2018 3:42 pm

Notxarb wrote:
Sun May 27, 2018 3:37 pm
PixelPest wrote:
Sun May 27, 2018 3:25 pm
Notxarb wrote:
Sun May 27, 2018 3:19 pm
How can you determine the distance between the player and the nearest block underneath them? Or at least detect if they are in mid-air?
You can check:

Code: Select all

not player:isGroundTouching()
Specifically what does this represent? (Slopes? NPCs?)
All of them

Novarender
Tweeter
Tweeter
Posts: 145
Joined: Sat Aug 06, 2016 6:59 pm
Flair: Whoa

Re: Need help with lua? - LunaLua General Help

Postby Novarender » Sun May 27, 2018 4:17 pm

If I define a variable without using "local", which other .lua files can access it? Is it the ones in the same level folder, episode folder, or the entirety of SMBX?

Mr Boboo
Spike
Spike
Posts: 267
Joined: Sat Jan 04, 2014 8:43 am
Flair: The Wicked Pissah

Re: Need help with lua? - LunaLua General Help

Postby Mr Boboo » Sun May 27, 2018 5:32 pm

Is it possible to despawn an NPC (without killing it) using Lua events?

Hoeloe
Phanto
Phanto
Posts: 1465
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Pronouns: she/her

Re: Need help with lua? - LunaLua General Help

Postby Hoeloe » Sun May 27, 2018 5:58 pm

Absolutely. That's how the magikoopa works if I remember correctly.

PixelPest
Link
Link
Posts: 7111
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Contact:

Re: Need help with lua? - LunaLua General Help

Postby PixelPest » Sun May 27, 2018 8:38 pm

Mr Boboo wrote:
Sun May 27, 2018 5:32 pm
Is it possible to despawn an NPC (without killing it) using Lua events?
Most definitely. If you look on the PGE Wiki you'll find some documentation of NPC memory fields. You'll need to set the NPC's offscreen timer to 0 iirc and make sure you set the respawn identity (another NPC field, set it to the NPC's ID)

The0x539
Eerie
Eerie
Posts: 751
Joined: Fri Jan 22, 2016 8:02 pm

Re: Need help with lua? - LunaLua General Help

Postby The0x539 » Mon May 28, 2018 12:42 am

Notxarb wrote:
Sun May 27, 2018 4:17 pm
If I define a variable without using "local", which other .lua files can access it? Is it the ones in the same level folder, episode folder, or the entirety of SMBX?
Red naxela wrote: So... if you declare something not as local, with the current Beta 4 code.... it depends where you do it.
1) If you do it in luna.lua/lunadll.lua/etc:
- If the non-local var matches the name of an event handler, it will be quarantined to JUST exist in that file
- Otherwise, it will be shared with all Lua code within the episode, but quarantined so it's not visible from basegame lua files
2) If you do it in libraries in episode/level folders:
- It is always shared with all Lua code within the episode, but quarantined so it's not visible from basegame lua files
3) If you do it in basegame lua code:
- It is always quarantined to JUST exist in that file
Typically in Lua, global variables go in a table called _G. If you explicitly put something in _G, like

Code: Select all

_G.myVar = 2
, then it'll be accessible everywhere, under most circumstances.
Red naxela wrote: Currently, if you write _G.foo it'll go everywhere in basically all cases.... BUT before beta 4 release I'm strongly considering locking it down so from episode/level code, _G only writes to the context for episode/level stuff

to keep episode/level code messing with _G from affecting core and basegame code
In Beta 3, globals in libraries are shared through the whole Lua shebang, and globals in lunadll.lua and the like aren't shared at all.

Taycamgame
Gold Yoshi Egg
Gold Yoshi Egg
Posts: 1483
Joined: Mon Jun 19, 2017 11:35 am
Flair: Stargard
Contact:

Re: Need help with lua? - LunaLua General Help

Postby Taycamgame » Mon May 28, 2018 4:53 am

So if you want a global collectible, say a special type of coin, you'd have to use global variables for it?
And where would you put the code for that - in the episode lunadll file, or in each level's lunadll file?

Hoeloe
Phanto
Phanto
Posts: 1465
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Pronouns: she/her

Re: Need help with lua? - LunaLua General Help

Postby Hoeloe » Mon May 28, 2018 6:30 am

No, you wouldn't use global variables for that. The Lua state resets every time you change levels or return to the overworld, so even if you had it saved in a global variable, the value would disappear.

You'd need to use the Data class in beta 3.

Novarender
Tweeter
Tweeter
Posts: 145
Joined: Sat Aug 06, 2016 6:59 pm
Flair: Whoa

Re: Need help with lua? - LunaLua General Help

Postby Novarender » Mon May 28, 2018 6:14 pm

So, how could I add to the save file of the episode using global variables? Or would I have to create my own save file? For instance, what if I want to save which Star Coins the player has collected so that when they save, close and exit it's still saved?

Also, unrelated, how can you "loop until"?

The0x539
Eerie
Eerie
Posts: 751
Joined: Fri Jan 22, 2016 8:02 pm

Re: Need help with lua? - LunaLua General Help

Postby The0x539 » Mon May 28, 2018 6:40 pm

Notxarb wrote:
Mon May 28, 2018 6:14 pm
So, how could I add to the save file of the episode using global variables? Or would I have to create my own save file? For instance, what if I want to save which Star Coins the player has collected so that when they save, close and exit it's still saved?

Also, unrelated, how can you "loop until"?
You wouldn't use global variables. Like Hoeloe said, you'd use the Data class.

Novarender
Tweeter
Tweeter
Posts: 145
Joined: Sat Aug 06, 2016 6:59 pm
Flair: Whoa

Re: Need help with lua? - LunaLua General Help

Postby Novarender » Mon May 28, 2018 7:53 pm

How do I set the player's animation?

PixelPest
Link
Link
Posts: 7111
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Contact:

Re: Need help with lua? - LunaLua General Help

Postby PixelPest » Tue May 29, 2018 7:50 am

Notxarb wrote:
Mon May 28, 2018 7:53 pm
How do I set the player's animation?
Check out the SMBX Player Offsets page on the PGE Wiki. You'll need to use the player:mem function to set the value at the address 0x114

Novarender
Tweeter
Tweeter
Posts: 145
Joined: Sat Aug 06, 2016 6:59 pm
Flair: Whoa

Re: Need help with lua? - LunaLua General Help

Postby Novarender » Tue May 29, 2018 3:35 pm

PixelPest wrote:
Tue May 29, 2018 7:50 am
Notxarb wrote:
Mon May 28, 2018 7:53 pm
How do I set the player's animation?
Check out the SMBX Player Offsets page on the PGE Wiki. You'll need to use the player:mem function to set the value at the address 0x114
I tried that, but I can't set it. In fact, I can't set any of the player offsets.

Code: Select all

player:mem(0x114, FIELD_WORD) = 24

PixelPest
Link
Link
Posts: 7111
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Contact:

Re: Need help with lua? - LunaLua General Help

Postby PixelPest » Tue May 29, 2018 3:44 pm

Notxarb wrote:
Tue May 29, 2018 3:35 pm
PixelPest wrote:
Tue May 29, 2018 7:50 am
Notxarb wrote:
Mon May 28, 2018 7:53 pm
How do I set the player's animation?
Check out the SMBX Player Offsets page on the PGE Wiki. You'll need to use the player:mem function to set the value at the address 0x114
I tried that, but I can't set it. In fact, I can't set any of the player offsets.

Code: Select all

player:mem(0x114, FIELD_WORD) = 24
If you look at the documentation that's not how it works. player:mem(0x114, FIELD_WORD) returns the value at the address 0x114 in the player memory struct. Basically you're trying to tell the code to set a number to another number. The player:mem (and all other mem functions in LunaLua) work a special way; put in two arguments and it'll return the associated value, add a third argument to set the value at the mem address.

>player:mem(0x114, FIELD_WORD)

a number

>player:mem(0x114, FIELD_WORD, 24)

address 0x114 set to 24

Novarender
Tweeter
Tweeter
Posts: 145
Joined: Sat Aug 06, 2016 6:59 pm
Flair: Whoa

Re: Need help with lua? - LunaLua General Help

Postby Novarender » Tue May 29, 2018 6:02 pm

Ok, I tried that but it's not doing anything.

Code: Select all

player:mem(0x114,FIELD_WORD,24)
At least it's not giving me an error.

EDIT: It's setting it to 24 every tick but then it's overidden by normal player animations. How can I stop this?

PixelPest
Link
Link
Posts: 7111
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Contact:

Re: Need help with lua? - LunaLua General Help

Postby PixelPest » Tue May 29, 2018 6:50 pm

Notxarb wrote:
Tue May 29, 2018 6:02 pm
Ok, I tried that but it's not doing anything.

Code: Select all

player:mem(0x114,FIELD_WORD,24)
At least it's not giving me an error.

EDIT: It's setting it to 24 every tick but then it's overidden by normal player animations. How can I stop this?
Perform anything graphics-related in onDraw


Return to “LunaLua”

Who is online

Users browsing this forum: No registered users and 1 guest

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari