Post here for help and support regarding LunaLua and SMBX2's libraries and features.
Moderator: Userbase Moderators
|
|
|
|
-
Emral
- Cute Yoshi Egg

- Posts: 9860
- Joined: Mon Jan 20, 2014 12:58 pm
- Flair: Phoenix
Postby Emral » Sat Mar 30, 2019 7:41 am
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!
Version 2.0
How to get started
LunaLua is SMBX2's programming language, so if you don't have SMBX2 in any capacity, you can download the most recent version from:
http://codehaus.wohlsoft.ru/downloads.html
If you're new to LunaLua, I suggest checking out my lua tutorials. I also recommend taking a look at the generic lua tutorial for a more technical focus on the language.
If you're looking for documentation of any kind, you're going to find it here.
The documentation above is not perfectly up-to-date at the current point in time, however, so for things not documented please take a look at the Handbook, or into the script files of the libraries you are trying to access.
We're working on getting a proper documentation set up in the coming months.
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.
|
|
|
|
|
|
|
|
|
-
boingboingsplat
- Goomba

- Posts: 4
- Joined: Mon Apr 01, 2019 11:40 am
Postby boingboingsplat » Mon Apr 01, 2019 9:41 pm
I made a slightly modified version of the Puntin' Chuck NPC, so that it could kick my own variant of the Football NPC.
However, I noticed something odd: It kicks half as often as the one I based it off of. Most of the code is the same, which made me curious, so I had it print off it's internal timer. It makes the issue apparent, it updates at half the rate, though I have no idea why.
Here's a clip of that happening: https://streamable.com/cbf23
Here's the full script for the sprite. Would love some guidance, is there something more I should be doing when making tweaked versions of NPCs that I neglected to do?
https://hastebin.com/uguwidoxij.rb
|
|
|
|
|
|
|
|
|
-
Quantumenace
- Ripper II

- Posts: 308
- Joined: Mon Dec 28, 2015 2:17 am
Postby Quantumenace » Tue Apr 02, 2019 12:19 am
It looks like the normal ones are too fast. Notice how their timer is always an even number? Maybe their behavior is being run twice for some reason.
|
|
|
|
|
|
|
|
|
-
boingboingsplat
- Goomba

- Posts: 4
- Joined: Mon Apr 01, 2019 11:40 am
Postby boingboingsplat » Tue Apr 02, 2019 1:40 am
Ah, nice call. I had created my own version of the Punting Chuck, to fix a bug, and just loaded it in my level over the same NPC ID. When I remove it the issue stops. My guess is, that maybe doing this causes the "onTickEndNPC" event to be registered twice? Causing its behavior to be executed twice per tick.
|
|
|
|
|
|
|
|
|
-
Hoeloe
- Foo

- Posts: 1465
- Joined: Sat Oct 03, 2015 6:18 pm
- Flair: The Codehaus Girl
- Pronouns: she/her
Postby Hoeloe » Tue Apr 02, 2019 5:41 am
boingboingsplat wrote: ↑Tue Apr 02, 2019 1:40 am
Ah, nice call. I had created my own version of the Punting Chuck, to fix a bug, and just loaded it in my level over the same NPC ID. When I remove it the issue stops. My guess is, that maybe doing this causes the "onTickEndNPC" event to be registered twice? Causing its behavior to be executed twice per tick.
If you use npc-#.lua files over an existing ID, it won't replace that NPCs behaviour, but run as well as the default behaviour. These files are for augmenting existing NPCs. If you want to create new ones from scratch, use IDs in the range 751-1000.
|
|
|
|
|
|
|
|
|
-
BigFrog
- Goomba

- Posts: 3
- Joined: Wed Apr 03, 2019 7:11 pm
- Flair: she/her
Postby BigFrog » Wed Apr 03, 2019 7:14 pm
I'm trying to make a special double jump but I'm having problems trying to define if the player is on the ground or not, and such is causing the double jump to go off instantly. Is there a way to define when the player is on the ground?
|
|
|
|
|
|
|
|
|
-
Hoeloe
- Foo

- Posts: 1465
- Joined: Sat Oct 03, 2015 6:18 pm
- Flair: The Codehaus Girl
- Pronouns: she/her
Postby Hoeloe » Thu Apr 04, 2019 2:26 pm
BigFrog wrote: ↑Wed Apr 03, 2019 7:14 pm
I'm trying to make a special double jump but I'm having problems trying to define if the player is on the ground or not, and such is causing the double jump to go off instantly. Is there a way to define when the player is on the ground?
|
|
|
|
|
|
|
|
|
-
Graham
- Cheep-Cheep

- Posts: 10
- Joined: Wed Jan 08, 2014 3:10 pm
Postby Graham » Fri Apr 05, 2019 4:41 pm
Silly question. Is there a way to access SMBX event fields from within LunaLua, such as the name of the fourth event in my level?
|
|
|
|
|
|
|
|
|
-
Dog In Da Grass
- Shy Guy

- Posts: 6
- Joined: Fri Nov 27, 2015 9:37 pm
Postby Dog In Da Grass » Fri Apr 05, 2019 6:02 pm
I've been trying to get this Blue Sproingy Thing to telliport to particular areas
I have it's X and Y co-ordinates listed by mario (the bottom two numbers)
but I dont know how to get it to move with Lua.
I tried using the npc.x = number and npc.y = number but it didnt change the location of the blue sproingy, is there a particular funtion to teliport npcs around? how could I achieve this?
Thanks, Woof!
|
|
|
|
|
|
|
|
|
-
Quantumenace
- Ripper II

- Posts: 308
- Joined: Mon Dec 28, 2015 2:17 am
Postby Quantumenace » Fri Apr 05, 2019 8:42 pm
Graham wrote: ↑Fri Apr 05, 2019 4:41 pm
Silly question. Is there a way to access SMBX event fields from within LunaLua, such as the name of the fourth event in my level?
Access it in what way? If you want to detect the event you use
function onEvent(eventName)
if eventName == "whateverYourEventNameIs" then
...
end
end
If you use onEventDirect(Event eventObj, string eventName) you can get the name field from the event object, but it doesn't look like there's an easy way to get the event from the event array itself.
Dog In Da Grass wrote:
I've been trying to get this Blue Sproingy Thing to telliport to particular areas
I have it's X and Y co-ordinates listed by mario (the bottom two numbers)
but I dont know how to get it to move with Lua.
I tried using the npc.x = number and npc.y = number but it didnt change the location of the blue sproingy, is there a particular funtion to teliport npcs around? how could I achieve this?
It's case sensitive, don't capitalize X and Y and see if that works.
|
|
|
|
|
|
|
|
|
-
Dog In Da Grass
- Shy Guy

- Posts: 6
- Joined: Fri Nov 27, 2015 9:37 pm
Postby Dog In Da Grass » Fri Apr 05, 2019 10:55 pm
Quantumenace wrote: ↑Fri Apr 05, 2019 8:42 pm
It's case sensitive, don't capitalize X and Y and see if that works.
lol, simple fix but it worked! Thank you!
|
|
|
|
|
|
|
|
|
-
Graham
- Cheep-Cheep

- Posts: 10
- Joined: Wed Jan 08, 2014 3:10 pm
Postby Graham » Sat Apr 06, 2019 1:35 am
Quantumenace wrote: ↑Fri Apr 05, 2019 8:42 pm
Access it in what way? If you want to detect the event you use
function onEvent(eventName)
if eventName == "whateverYourEventNameIs" then
...
end
end
If you use onEventDirect(Event eventObj, string eventName) you can get the name field from the event object, but it doesn't look like there's an easy way to get the event from the event array itself.
Unfortunately, access in the sense of get and set the raw fields from the event array. I'd been doing a bit of experimenting to try to give a more useful bug report, and I'd noticed that the bug where game end doesn't, well, end the game, only seems to occur when game end is called from an event. Calling game end directly from Lua and killing Bowser when legacy boss is set both seem to end the game properly, so I wanted to test if that has to do with the associated event field not being loaded with its proper value somehow. But it doesn't seem like there's a nice way to do that as is - ah well.
Thanks a lot for the help!
|
|
|
|
|
|
|
|
|
-
BabyPinkSnail
- Goomba

- Posts: 4
- Joined: Mon Jul 23, 2018 6:59 pm
- Pronouns: she/her
-
Contact:
Postby BabyPinkSnail » Sun Apr 07, 2019 5:41 am
I wanna make it so the player is big at the start of the level but only at the very start so after you've gotten a checkpoint you'll spawn small, however I'm assuming level start means anytime the level is started the first time, or after a checkpoint, please tell me how to do it I've tried a few options and feel like an event trigger isn't probably the most optimized way to do it.
|
|
|
|
|
|
|
|
|
-
Hoeloe
- Foo

- Posts: 1465
- Joined: Sat Oct 03, 2015 6:18 pm
- Flair: The Codehaus Girl
- Pronouns: she/her
Postby Hoeloe » Sun Apr 07, 2019 7:22 am
You can actually check if you're spawning from a checkpoint pretty easily:
Code: Select all function onStart()
if Checkpoint.get() == nil then
player.powerup = 2
end
end
Should work.
|
|
|
|
|
|
|
|
|
-
Murphmario
- 2025 Egg Hunter

- Posts: 2389
- Joined: Fri Dec 20, 2013 7:07 pm
- Pronouns: he/him
Postby Murphmario » Mon Apr 08, 2019 4:19 pm
Hey, does anyone know why I'm getting this error? It's not an issue with Enjl's Parachute NPCs, so something must be wrong with my file.

|
|
|
|
|
|
|
|
|
-
Hoeloe
- Foo

- Posts: 1465
- Joined: Sat Oct 03, 2015 6:18 pm
- Flair: The Codehaus Girl
- Pronouns: she/her
Postby Hoeloe » Mon Apr 08, 2019 5:08 pm
Murphmario wrote: ↑Mon Apr 08, 2019 4:19 pm
Hey, does anyone know why I'm getting this error? It's not an issue with Enjl's Parachute NPCs, so something must be wrong with my file.
If I'm right, your code will have a line with something like:
Code: Select all npcmanager.registerDefines(NPC_ID, NPC_HITTABLE)
or something similar.
When using registerDefines, you have to supply a list of NPC styles, even if that list has only one item, like so:
Code: Select all npcmanager.registerDefines(NPC_ID, {NPC_HITTABLE})
|
|
|
|
|
|
|
|
|
-
cato
- Volcano Lotus

- Posts: 554
- Joined: Thu Aug 24, 2017 3:06 am
- Flair: Koishi enjoyer
-
Contact:
Postby cato » Thu Apr 18, 2019 9:13 am
Straight up copies from Enjl's video. Still doesn't work. I got some problems.The thing is, the counter doesn't even add 1.
Code: Select all local counter = 0
SaveData[Level.filename()] = SaveData[Level.filename()] or {}
local levelSD = SaveData[Level.filename()]
function onStart()
player.character=CHARACTER_TOAD
player.powerup=PLAYER_BIG
if levelSD.dragonCoinsCollected then
for k,v in ipairs(NPC.get(274)) do
v:kill(9)
end
end
end
function onDraw()
Text.print(counter,100 ,100)
if SaveData[Level.filename()].dragonCoinsCollected then
Text.print("Good job player!")
end
end
function onNPCkill(eventObj, killedNPC, killReason)
if killedNPC.id ~= 274 then return end
if killReason ~= HARM_TYPE_OFFSCREEN then return end
if Colliders.collide(player, killedNPC) then
counter = counter+1
if counter == 5 then
levelSD.dragonCoinsCollected = true
end
end
end
|
|
|
|
|
|
|
|
|
-
Emral
- Cute Yoshi Egg

- Posts: 9860
- Joined: Mon Jan 20, 2014 12:58 pm
- Flair: Phoenix
Postby Emral » Thu Apr 18, 2019 10:24 am
onNPCKill. Case-sensitivity.
|
|
|
|
|
|
|
|
|
-
Dog In Da Grass
- Shy Guy

- Posts: 6
- Joined: Fri Nov 27, 2015 9:37 pm
Postby Dog In Da Grass » Sun Apr 21, 2019 5:47 pm
is there a way to modify any of the characters? is there a way to have and change a personal copy of the lua file for your level folder?
More specifically I've been trying to edit Klonoa so you can interupt his flutter and also move while shooting the ring
I've been looking at the code and I think I found exactly what I want, I just don't know how to access it from my own lua file
I'd like to change flaptimer but, yeah, don't quite know how to go about this, do any of you have any ideas? thanks~
EDIT
Found help elsewhere, I needed to have a "Characters" folder in my level file
Added in 1 hour 12 minutes 27 seconds:
Though a previous question I have still stands,
how do I switch to a custom character?
|
|
|
|
|
|
|
|
|
-
Emral
- Cute Yoshi Egg

- Posts: 9860
- Joined: Mon Jan 20, 2014 12:58 pm
- Flair: Phoenix
Postby Emral » Sun Apr 21, 2019 7:46 pm
Dog In Da Grass wrote: ↑Sun Apr 21, 2019 7:03 pm
how do I switch to a custom character?
You can use the character constants: player:transform(CHARACTER_KLONOA)
|
|
|
|
|
Return to “LunaLua Help”
Users browsing this forum: No registered users and 1 guest
|