Post here for help and support regarding LunaLua and SMBX2's libraries and features.
Moderator: Userbase Moderators
|
|
|
|
-
Marioman2007
- 2025 Egg Hunter

- Posts: 527
- Joined: Tue Aug 25, 2020 3:19 am
- Flair: Dr. Bones
- Pronouns: He/Him
Postby Marioman2007 » Sun Mar 24, 2024 11:02 am
Does "if sectionIdx == 1 then" work for your case?
|
|
|
|
|
|
|
|
|
-
Just_Thomas
- Spike

- Posts: 296
- Joined: Sat Dec 16, 2023 3:32 am
- Pronouns: he/him
Postby Just_Thomas » Sun Mar 24, 2024 11:36 am
Marioman2007 wrote: ↑Sun Mar 24, 2024 11:02 am
Does "if sectionIdx == 1 then" work for your case?
I was THAT close? Eeeeh... yes, this does the trick, I just checked and tested.
Thanks and BTW: Forgot about you in that moment, you also helped me quite a lot. (:
|
|
|
|
|
|
|
|
|
-
mariobrigade2018
- Rocky Wrench

- Posts: 607
- Joined: Wed May 24, 2023 7:00 pm
- Flair: OK in coding who dreams of making a Mario game
- Pronouns: he/him
Postby mariobrigade2018 » Tue Apr 16, 2024 3:36 pm
How do I make RNG non-inclusive?
|
|
|
|
|
|
|
|
|
-
Just_Thomas
- Spike

- Posts: 296
- Joined: Sat Dec 16, 2023 3:32 am
- Pronouns: he/him
Postby Just_Thomas » Fri Apr 26, 2024 2:51 pm
Is it actually possible to work with something like this? (Hint: It is not actual real working code, it is only written that way so that it is immediately clear what I mean/try to say):
Code: Select all function onStart()
if checkpoint1:collect() == true then
...
end
end
During normal gameplay, the SMW-typical checkpoint is saved as "activated", so I'm wondering whether you could work with something like this and query it at the start of the game.
Since I have too little knowledge, I hope someone from the development team can tell me briefly and concisely whether this works.
|
|
|
|
|
|
|
|
|
-
deice
- Volcano Lotus

- Posts: 596
- Joined: Fri Jul 23, 2021 7:35 am
Postby deice » Sat Apr 27, 2024 6:43 am
Just_Thomas wrote: ↑Fri Apr 26, 2024 2:51 pm
During normal gameplay, the SMW-typical checkpoint is saved as "activated", so I'm wondering whether you could work with something like this and query it at the start of the game.
you're probably looking for something like this:
Code: Select all function onStart()
local c = Checkpoint.getActive()
-- the variable c now holds a reference to the active checkpoint object, or nil if there's no active checkpoint in the current level
if(c) then
-- execute code here if the checkpoint exists
end
end
unfortunately i don't think the checkpoint class documentation is finished, but if memory serves me right you should be able to at least poll for its position and section.
|
|
|
|
|
|
|
|
|
-
Just_Thomas
- Spike

- Posts: 296
- Joined: Sat Dec 16, 2023 3:32 am
- Pronouns: he/him
Postby Just_Thomas » Sat Apr 27, 2024 7:37 am
deice wrote: ↑Sat Apr 27, 2024 6:43 am
Just_Thomas wrote: ↑Fri Apr 26, 2024 2:51 pm
During normal gameplay, the SMW-typical checkpoint is saved as "activated", so I'm wondering whether you could work with something like this and query it at the start of the game.
you're probably looking for something like this:
Code: Select all function onStart()
local c = Checkpoint.getActive()
-- the variable c now holds a reference to the active checkpoint object, or nil if there's no active checkpoint in the current level
if(c) then
-- execute code here if the checkpoint exists
end
end
unfortunately i don't think the checkpoint class documentation is finished, but if memory serves me right you should be able to at least poll for its position and section.
First, thanks for your reply as usual.
Actually I wouldn`t have guessed the docu is NOT finished (so it is updated to beta 5 as stated on the "welcome Screen" but old stuff is still missing?).
Code: Select all local checkpoints = require("checkpoints")
local cp1 = checkpoints.create{x = -103104, y = -100128, section = 5}
So, I had a checkpoint already (still thanking Emral for telling me how to do that).
ok, I then adapted the code for my test:
Code: Select all function onStart()
local c1 = cp1.getActive()
-- the variable c now holds a reference to the active checkpoint object, or nil if there's no active checkpoint in the current level
if(c1) then
Routine.run(VineInSky)
end
...
(yes, the routine mentioned does exist as well and does work properly)
Just starting the level gives me this error

|
|
|
|
|
|
|
|
|
-
deice
- Volcano Lotus

- Posts: 596
- Joined: Fri Jul 23, 2021 7:35 am
Postby deice » Sat Apr 27, 2024 9:30 am
Just_Thomas wrote: ↑Sat Apr 27, 2024 7:37 am
Just starting the level gives me this error
this is because you're calling "getActive" on an already-instanced checkpoint instead of statically on the Checkpoint class. the code i posted is meant to be used verbatim; getActive will return the currently active checkpoint within the level, whichever one that may be.
|
|
|
|
|
|
|
|
|
-
Marioman2007
- 2025 Egg Hunter

- Posts: 527
- Joined: Tue Aug 25, 2020 3:19 am
- Flair: Dr. Bones
- Pronouns: He/Him
Postby Marioman2007 » Sat Apr 27, 2024 9:33 am
Checkpoint.getActive() returns the currently active checkpoint.
Try this code and see if it works as intended.
Code: Select all local cp1 = Checkpoint{x = -103104, y = -100128, section = 5}
function onStart()
if Checkpoint.getActive() == cp1 then
Routine.run(VineInSky)
end
end
|
|
|
|
|
|
|
|
|
-
Just_Thomas
- Spike

- Posts: 296
- Joined: Sat Dec 16, 2023 3:32 am
- Pronouns: he/him
Postby Just_Thomas » Sat Apr 27, 2024 12:02 pm
deice wrote: ↑Sat Apr 27, 2024 9:30 am
this is because you're calling "getActive" on an already-instanced checkpoint instead of statically on the Checkpoint class. the code i posted is meant to be used verbatim; getActive will return the currently active checkpoint within the level, whichever one that may be.
Marioman2007 wrote: ↑Sat Apr 27, 2024 9:33 am
Checkpoint.getActive() returns the currently active checkpoint.
Try this code and see if it works as intended.
It's kind of funny, now that you see it, it kind of makes sense. If CP1 is the active checkpoint, then do that... yes, you're always smarter afterwards.
Unfortunately, after an intensive thinking phase (I actually really mean it  ), I came to the realization that this is not at all useful for the implementation of my solution approach at all (sorry to both of you).
That is because I already made use of
Code: Select all function onStart()
...
if player.x == ... and player.section == ... then
--do stuff
end
...
The thing is I still have my other project in the pipeline where I wanted the show the player some kind of "intro image" at the beginning (SMB1 you know).
Yes, Emral might remember - if you read it. To be honest however it did not work out well and caused annoying random bugs here and there (sometimes the intro image did not appear in the first place e.g.).
Anyway: I figured a solution, it looks terrible, you might laugh and shake your head, facepalm and whatever. But it seems to work (Hint: If there is a LESS complicated way to realize it, please tell me)
I was surprised BTW it is not possible to create a warp like creating a checkpoint, at least I could not find anything like that.
Code: Select all --------------------------------------------------
-- Level code
-- Created 16:34 2024-4-27
--------------------------------------------------
local checkpoints = require("checkpoints")
local cp1 = checkpoints.create{x = -179296, y = -180128, section = 1}
local cp2 = checkpoints.create{x = -177728, y = -180128, section = 1}
function onStart()
local warpStart1Layer = Layer.get("warpStart1")
local warpStart2Layer = Layer.get("warpStart2")
local warpStart3Layer = Layer.get("warpStart3")
warpStart1Layer:show(true)
warpStart2Layer:hide(true)
warpStart3Layer:hide(true)
local warpCP1Layer = Layer.get("warpCheckpoint1")
local warpCP2Layer = Layer.get("warpCheckpoint2")
warpCP1Layer:hide(true)
warpCP2Layer:hide(true)
--checkpoint 1
if player.x == -179308 and player.section == 1 then
Routine.run(checkPoint1R)
end
--checkpoint 2
if player.x == -177740 and player.section == 1 then
Routine.run(checkPoint2R)
end
end
function onTick()
--Text.print(player.x, 100, 100)
end
function checkPoint1R()
local warpCP1Layer = Layer.get("warpCheckpoint1")
warpCP1Layer:show(true)
local warpStart2Layer = Layer.get("warpStart2")
local warpStart1Layer = Layer.get("warpStart1")
warpStart2Layer:show(true)
warpStart1Layer:hide(true)
Routine.waitSeconds(1.0, true)
warpCP1Layer:hide(true)
end
function checkPoint2R()
local warpCP2Layer = Layer.get("warpCheckpoint2")
warpCP2Layer:show(true)
local warpStart3Layer = Layer.get("warpStart3")
local warpStart1Layer = Layer.get("warpStart1")
warpStart3Layer:show(true)
warpStart1Layer:hide(true)
Routine.waitSeconds(1.0, true)
warpCP2Layer:hide(true)
end
Also as a download here:
https://file.io/LaR8glu3ZVHw
or
https://www.file-upload.net/download-15 ... f.zip.html
or
https://fastupload.io/TQrQnRQi1NO0aON/file
Edit: Ok, it was NOT for nothing as this is a little bit less complicated indeed
Code: Select all ...
--checkpoint 1
if Checkpoint.getActive() == cp1 then
Routine.run(checkPoint1R)
end
--checkpoint 2
if Checkpoint.getActive() == cp2 then
Routine.run(checkPoint2R)
end
...
works the same 
|
|
|
|
|
|
|
|
|
-
Mesi
- Goomba

- Posts: 1
- Joined: Thu Sep 19, 2024 3:21 pm
- Flair: Hi! ;)
- Pronouns: He/Him
Postby Mesi » Thu Sep 19, 2024 3:44 pm
Hi! I'm trying to create some particles effects for my project and I keep getting this error :/
I'm following a pretty "simple" tutorial I found ( https://www.youtube.com/watch?v=yZbT10G ... nnel=Emral) and I'm stuck literally at the second point ahahah
Like the tutorial says I'm using the template for particles effect called "particles_example.ini" that can be found in the templates folder (but it's like it can't be read)
I wrote this in my luna.lua file:
Code: Select all local particles = require("particles")
local sparkleEmitter = particles.Emitter(0, 0, "particles_example.ini")
function onStart()
sparkleEmitter:Attach(player)
end
Thank you for the help! 
|
|
|
|
|
|
|
|
|
-
InternetPeasent
- Spiny

- Posts: 28
- Joined: Sat Sep 04, 2021 12:33 pm
- Pronouns: he/him
-
Contact:
Postby InternetPeasent » Mon Oct 14, 2024 9:20 pm
In a library, I'm trying to run a bit of code only when the player gets a specific exit type. First I tried registering the event in onInitAPI() like this:
Code: Select all registerEvent(progDifficulty, 7, "onExitLevel")
However, the event refused to work, even when I got the specified exit type. I also tried checking for the exit type instead, in an if statement like so:
Code: Select all function progDifficulty.onExitLevel()
if Level.endState() == 6 then
SaveData.Difficulty = SaveData.Difficulty + 1
end
end
...but that didn't work either. I'm also positive I'm not getting win types and end states mixed up. Does anyone know what I might be doing wrong?
|
|
|
|
|
|
|
|
|
-
Marioman2007
- 2025 Egg Hunter

- Posts: 527
- Joined: Tue Aug 25, 2020 3:19 am
- Flair: Dr. Bones
- Pronouns: He/Him
Postby Marioman2007 » Mon Oct 14, 2024 9:51 pm
InternetPeasent wrote: ↑Mon Oct 14, 2024 9:20 pm
In a library, I'm trying to run a bit of code only when the player gets a specific exit type. First I tried registering the event in onInitAPI() like this:
Code: Select all registerEvent(progDifficulty, 7, "onExitLevel")
However, the event refused to work, even when I got the specified exit type. I also tried checking for the exit type instead, in an if statement like so:
Code: Select all function progDifficulty.onExitLevel()
if Level.endState() == 6 then
SaveData.Difficulty = SaveData.Difficulty + 1
end
end
...but that didn't work either. I'm also positive I'm not getting win types and end states mixed up. Does anyone know what I might be doing wrong?
The way you're registering the event is wrong
Code: Select all registerEvent(progDifficulty, "onExitLevel")
function progDifficulty.onExitLevel(w)
if w == 6 then
SaveData.Difficulty = SaveData.Difficulty + 1
end
end
|
|
|
|
|
|
|
|
|
-
InternetPeasent
- Spiny

- Posts: 28
- Joined: Sat Sep 04, 2021 12:33 pm
- Pronouns: he/him
-
Contact:
Postby InternetPeasent » Mon Oct 14, 2024 10:18 pm
Marioman2007 wrote: ↑Mon Oct 14, 2024 9:51 pm
InternetPeasent wrote: ↑Mon Oct 14, 2024 9:20 pm
In a library, I'm trying to run a bit of code only when the player gets a specific exit type. First I tried registering the event in onInitAPI() like this:
Code: Select all registerEvent(progDifficulty, 7, "onExitLevel")
However, the event refused to work, even when I got the specified exit type. I also tried checking for the exit type instead, in an if statement like so:
Code: Select all function progDifficulty.onExitLevel()
if Level.endState() == 6 then
SaveData.Difficulty = SaveData.Difficulty + 1
end
end
...but that didn't work either. I'm also positive I'm not getting win types and end states mixed up. Does anyone know what I might be doing wrong?
The way you're registering the event is wrong
Code: Select all registerEvent(progDifficulty, "onExitLevel")
function progDifficulty.onExitLevel(w)
if w == 6 then
SaveData.Difficulty = SaveData.Difficulty + 1
end
end
Thank you, this got the code working!
|
|
|
|
|
|
|
|
|
-
andrei312g
- Shy Guy

- Posts: 7
- Joined: Tue Oct 22, 2024 10:38 am
- Pronouns: he/him
Postby andrei312g » Tue Oct 22, 2024 11:05 am
Emral wrote: ↑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.
Hello! I downloaded the SMBX2 (SMBX2b5p2 version) on a new laptop and I have a problem with the scripts. I am trying to load an HUD script downloaded from LunaLUA forum on a game that I'm working on and it's not working with the new versions. I tried the script on SMBX 2.0 Beta 3 version and it worked, but it's not working on newer versions, such as SMBX2b5p2 version that I'm using right now. How can I load this script on the SMBX2b5p2 version (this version that I have right now: latest version)?
Here is the log that it gave me:
Code: Select all ==> E:\SMBX2\data/scripts/base/engine/require.lua:118: module 'minHUD' not found
=============
stack traceback:
E:\SMBX2\data/scripts/base/engine/require.lua:118: in function 'require'
...(*game (folder) that I'm working on*)/luna.lua:2: in function 'codeFile'
main.lua:742: in function 'loadCodeFile'
main.lua:888: in function <main.lua:792> [C]: in function '__xpcall'
main.lua:792: in function <main.lua:791>
I tried with the SMB3 overhaul HUD script too.
The log that it gave me when I tried to load:
Code: Select all ==> scripts/base/engine/ffi_npc.lua:280: Invalid NPC index (11)
=============
stack traceback:
scripts/base/engine/ffi_npc.lua:280: in function 'NPC'
scripts/smb3overhaul.lua:50: in function 'func'
E:\SMBX2\data/scripts/base/engine/require.lua:150: in function 'require'
...(*game (folder) that I'm working on*)/luna.lua:2: in function 'codeFile'
main.lua:742: in function 'loadCodeFile'
main.lua:888: in function <main.lua:792> [C]: in function '__xpcall'
main.lua:792: in function <main.lua:791>
Can you help me fix this problem?
|
|
|
|
|
|
|
|
|
-
mariobrigade2018
- Rocky Wrench

- Posts: 607
- Joined: Wed May 24, 2023 7:00 pm
- Flair: OK in coding who dreams of making a Mario game
- Pronouns: he/him
Postby mariobrigade2018 » Wed Oct 23, 2024 11:44 am
andrei312g wrote: ↑Tue Oct 22, 2024 11:05 am
Here is the log that it gave me:
Code: Select all ==> E:\SMBX2\data/scripts/base/engine/require.lua:118: module 'minHUD' not found
=============
stack traceback:
E:\SMBX2\data/scripts/base/engine/require.lua:118: in function 'require'
...(*game (folder) that I'm working on*)/luna.lua:2: in function 'codeFile'
main.lua:742: in function 'loadCodeFile'
main.lua:888: in function <main.lua:792> [C]: in function '__xpcall'
main.lua:792: in function <main.lua:791>
The log that it gave me when I tried to load:
Code: Select all ==> scripts/base/engine/ffi_npc.lua:280: Invalid NPC index (11)
=============
stack traceback:
scripts/base/engine/ffi_npc.lua:280: in function 'NPC'
scripts/smb3overhaul.lua:50: in function 'func'
E:\SMBX2\data/scripts/base/engine/require.lua:150: in function 'require'
...(*game (folder) that I'm working on*)/luna.lua:2: in function 'codeFile'
main.lua:742: in function 'loadCodeFile'
main.lua:888: in function <main.lua:792> [C]: in function '__xpcall'
main.lua:792: in function <main.lua:791>
Looks like you’re missing a require call somewhere in your first message. And SMB3override is super ancient code, which is why it doesn’t work.
Also why did you quote the entire first message of the topic? That wasn’t necessary.
|
|
|
|
|
|
|
|
|
-
andrei312g
- Shy Guy

- Posts: 7
- Joined: Tue Oct 22, 2024 10:38 am
- Pronouns: he/him
Postby andrei312g » Wed Oct 23, 2024 2:51 pm
mariobrigade2018 wrote: ↑Wed Oct 23, 2024 11:44 am
andrei312g wrote: ↑Tue Oct 22, 2024 11:05 am
Here is the log that it gave me:
Code: Select all ==> E:\SMBX2\data/scripts/base/engine/require.lua:118: module 'minHUD' not found
=============
stack traceback:
E:\SMBX2\data/scripts/base/engine/require.lua:118: in function 'require'
...(*game (folder) that I'm working on*)/luna.lua:2: in function 'codeFile'
main.lua:742: in function 'loadCodeFile'
main.lua:888: in function <main.lua:792> [C]: in function '__xpcall'
main.lua:792: in function <main.lua:791>
The log that it gave me when I tried to load:
Code: Select all ==> scripts/base/engine/ffi_npc.lua:280: Invalid NPC index (11)
=============
stack traceback:
scripts/base/engine/ffi_npc.lua:280: in function 'NPC'
scripts/smb3overhaul.lua:50: in function 'func'
E:\SMBX2\data/scripts/base/engine/require.lua:150: in function 'require'
...(*game (folder) that I'm working on*)/luna.lua:2: in function 'codeFile'
main.lua:742: in function 'loadCodeFile'
main.lua:888: in function <main.lua:792> [C]: in function '__xpcall'
main.lua:792: in function <main.lua:791>
Looks like you’re missing a require call somewhere in your first message. And SMB3override is super ancient code, which is why it doesn’t work.
Also why did you quote the entire first message of the topic? That wasn’t necessary.
I only typed this for minHUD. I don't know what's missing.

|
|
|
|
|
|
|
|
|
-
mariobrigade2018
- Rocky Wrench

- Posts: 607
- Joined: Wed May 24, 2023 7:00 pm
- Flair: OK in coding who dreams of making a Mario game
- Pronouns: he/him
Postby mariobrigade2018 » Wed Oct 23, 2024 4:19 pm
andrei312g wrote: ↑Wed Oct 23, 2024 2:51 pm
mariobrigade2018 wrote: ↑Wed Oct 23, 2024 11:44 am
andrei312g wrote: ↑Tue Oct 22, 2024 11:05 am
Here is the log that it gave me:
Code: Select all ==> E:\SMBX2\data/scripts/base/engine/require.lua:118: module 'minHUD' not found
=============
stack traceback:
E:\SMBX2\data/scripts/base/engine/require.lua:118: in function 'require'
...(*game (folder) that I'm working on*)/luna.lua:2: in function 'codeFile'
main.lua:742: in function 'loadCodeFile'
main.lua:888: in function <main.lua:792> [C]: in function '__xpcall'
main.lua:792: in function <main.lua:791>
The log that it gave me when I tried to load:
Code: Select all ==> scripts/base/engine/ffi_npc.lua:280: Invalid NPC index (11)
=============
stack traceback:
scripts/base/engine/ffi_npc.lua:280: in function 'NPC'
scripts/smb3overhaul.lua:50: in function 'func'
E:\SMBX2\data/scripts/base/engine/require.lua:150: in function 'require'
...(*game (folder) that I'm working on*)/luna.lua:2: in function 'codeFile'
main.lua:742: in function 'loadCodeFile'
main.lua:888: in function <main.lua:792> [C]: in function '__xpcall'
main.lua:792: in function <main.lua:791>
Looks like you’re missing a require call somewhere in your first message. And SMB3override is super ancient code, which is why it doesn’t work.
I only typed this for minHUD. I don't know what's missing.
Where is minHUD located?
|
|
|
|
|
|
|
|
|
-
andrei312g
- Shy Guy

- Posts: 7
- Joined: Tue Oct 22, 2024 10:38 am
- Pronouns: he/him
Postby andrei312g » Thu Oct 24, 2024 9:36 am
mariobrigade2018 wrote: ↑Wed Oct 23, 2024 4:19 pm
andrei312g wrote: ↑Wed Oct 23, 2024 2:51 pm
mariobrigade2018 wrote: ↑Wed Oct 23, 2024 11:44 am
Looks like you’re missing a require call somewhere in your first message. And SMB3override is super ancient code, which is why it doesn’t work.
I only typed this for minHUD. I don't know what's missing.
Where is minHUD located?
here in scripts folder

|
|
|
|
|
|
|
|
|
-
mariobrigade2018
- Rocky Wrench

- Posts: 607
- Joined: Wed May 24, 2023 7:00 pm
- Flair: OK in coding who dreams of making a Mario game
- Pronouns: he/him
Postby mariobrigade2018 » Thu Oct 24, 2024 11:07 am
andrei312g wrote: ↑Thu Oct 24, 2024 9:36 am
mariobrigade2018 wrote: ↑Wed Oct 23, 2024 4:19 pm
andrei312g wrote: ↑Wed Oct 23, 2024 2:51 pm
I only typed this for minHUD. I don't know what's missing.
Where is minHUD located?
here in scripts folder
That looks like the basegame scripts folder. Don’t put it there. Put it in the same place as where the luna.lua file is.
|
|
|
|
|
|
|
|
|
-
jokyaku
- Goomba

- Posts: 4
- Joined: Thu Jan 20, 2022 7:44 am
- Pronouns: he/him
Postby jokyaku » Thu Jan 09, 2025 4:58 pm
Hello! I'm currently just finishing a custom NPC and I was wondering if there was any way of using Extra Settings to alter an NPC Config such as nofireball or jumphurt.
|
|
|
|
|
Return to “LunaLua Help”
Users browsing this forum: No registered users and 1 guest
|