Page 66 of 76
Re: Need help with lua? - LunaLua General Help
Posted: Sat May 26, 2018 8:13 am
by cato
How to make autoscroll in other sections ? If possible......
Re: Need help with lua? - LunaLua General Help
Posted: Sun May 27, 2018 3:19 pm
by Novarender
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?
Re: Need help with lua? - LunaLua General Help
Posted: Sun May 27, 2018 3:25 pm
by PixelPest
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:
Re: Need help with lua? - LunaLua General Help
Posted: Sun May 27, 2018 3:37 pm
by Novarender
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:
Specifically what does this represent? (Slopes? NPCs?)
Re: Need help with lua? - LunaLua General Help
Posted: Sun May 27, 2018 3:42 pm
by PixelPest
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:
Specifically what does this represent? (Slopes? NPCs?)
All of them
Re: Need help with lua? - LunaLua General Help
Posted: Sun May 27, 2018 4:17 pm
by Novarender
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?
Re: Need help with lua? - LunaLua General Help
Posted: Sun May 27, 2018 5:32 pm
by Mr Boboo
Is it possible to despawn an NPC (without killing it) using Lua events?
Re: Need help with lua? - LunaLua General Help
Posted: Sun May 27, 2018 5:58 pm
by Hoeloe
Absolutely. That's how the magikoopa works if I remember correctly.
Re: Need help with lua? - LunaLua General Help
Posted: Sun May 27, 2018 8:38 pm
by PixelPest
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)
Re: Need help with lua? - LunaLua General Help
Posted: Mon May 28, 2018 12:42 am
by The0x539
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
, 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.
Re: Need help with lua? - LunaLua General Help
Posted: Mon May 28, 2018 4:53 am
by Taycamgame
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?
Re: Need help with lua? - LunaLua General Help
Posted: Mon May 28, 2018 6:30 am
by Hoeloe
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.
Re: Need help with lua? - LunaLua General Help
Posted: Mon May 28, 2018 6:14 pm
by Novarender
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"?
Re: Need help with lua? - LunaLua General Help
Posted: Mon May 28, 2018 6:40 pm
by The0x539
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.
Re: Need help with lua? - LunaLua General Help
Posted: Mon May 28, 2018 7:53 pm
by Novarender
How do I set the player's animation?
Re: Need help with lua? - LunaLua General Help
Posted: Tue May 29, 2018 7:50 am
by PixelPest
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
Re: Need help with lua? - LunaLua General Help
Posted: Tue May 29, 2018 3:35 pm
by Novarender
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
Re: Need help with lua? - LunaLua General Help
Posted: Tue May 29, 2018 3:44 pm
by PixelPest
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
Re: Need help with lua? - LunaLua General Help
Posted: Tue May 29, 2018 6:02 pm
by Novarender
Ok, I tried that but it's not doing anything.
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?
Re: Need help with lua? - LunaLua General Help
Posted: Tue May 29, 2018 6:50 pm
by PixelPest
Notxarb wrote: ↑Tue May 29, 2018 6:02 pm
Ok, I tried that but it's not doing anything.
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