Re: Need help with lua? - LunaLua General Help
Posted: Sun Mar 24, 2024 11:02 am
Does "if sectionIdx == 1 then" work for your case?
Forums for SMBX
https://www.smbxgame.com/forums/
I was THAT close? Eeeeh... yes, this does the trick, I just checked and tested.
Code: Select all
function onStart()
if checkpoint1:collect() == true then
...
end
end
you're probably looking for something like this:Just_Thomas wrote: ↑Fri Apr 26, 2024 2:51 pmDuring 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.
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
First, thanks for your reply as usual.deice wrote: ↑Sat Apr 27, 2024 6:43 amyou're probably looking for something like this:Just_Thomas wrote: ↑Fri Apr 26, 2024 2:51 pmDuring 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.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.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
Code: Select all
local checkpoints = require("checkpoints")
local cp1 = checkpoints.create{x = -103104, y = -100128, section = 5}
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
...
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.
Code: Select all
local cp1 = Checkpoint{x = -103104, y = -100128, section = 5}
function onStart()
if Checkpoint.getActive() == cp1 then
Routine.run(VineInSky)
end
end
deice wrote: ↑Sat Apr 27, 2024 9:30 amthis 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.
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.Marioman2007 wrote: ↑Sat Apr 27, 2024 9:33 amCheckpoint.getActive() returns the currently active checkpoint.
Try this code and see if it works as intended.
Code: Select all
function onStart()
...
if player.x == ... and player.section == ... then
--do stuff
end
...
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
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
...
Code: Select all
local particles = require("particles")
local sparkleEmitter = particles.Emitter(0, 0, "particles_example.ini")
function onStart()
sparkleEmitter:Attach(player)
end
Code: Select all
registerEvent(progDifficulty, 7, "onExitLevel")
Code: Select all
function progDifficulty.onExitLevel()
if Level.endState() == 6 then
SaveData.Difficulty = SaveData.Difficulty + 1
end
end
InternetPeasent wrote: ↑Mon Oct 14, 2024 9:20 pmIn 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: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
registerEvent(progDifficulty, 7, "onExitLevel")
...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?Code: Select all
function progDifficulty.onExitLevel() if Level.endState() == 6 then SaveData.Difficulty = SaveData.Difficulty + 1 end end
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!Marioman2007 wrote: ↑Mon Oct 14, 2024 9:51 pmInternetPeasent wrote: ↑Mon Oct 14, 2024 9:20 pmIn 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: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
registerEvent(progDifficulty, 7, "onExitLevel")
...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?Code: Select all
function progDifficulty.onExitLevel() if Level.endState() == 6 then SaveData.Difficulty = SaveData.Difficulty + 1 end end
The way you're registering the event is wrongCode: Select all
registerEvent(progDifficulty, "onExitLevel") function progDifficulty.onExitLevel(w) if w == 6 then SaveData.Difficulty = SaveData.Difficulty + 1 end end
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)?Emral wrote: ↑Sat Mar 30, 2019 7:41 amSo 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.
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>
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.andrei312g wrote: ↑Tue Oct 22, 2024 11:05 amHere is the log that it gave me:The log that it gave me when I tried to load: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>
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>
I only typed this for minHUD. I don't know what's missing.mariobrigade2018 wrote: ↑Wed Oct 23, 2024 11:44 amLooks 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.andrei312g wrote: ↑Tue Oct 22, 2024 11:05 amHere is the log that it gave me:The log that it gave me when I tried to load: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>
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>
Also why did you quote the entire first message of the topic? That wasn’t necessary.
Where is minHUD located?andrei312g wrote: ↑Wed Oct 23, 2024 2:51 pmI only typed this for minHUD. I don't know what's missing.mariobrigade2018 wrote: ↑Wed Oct 23, 2024 11:44 amLooks 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.andrei312g wrote: ↑Tue Oct 22, 2024 11:05 amHere is the log that it gave me:The log that it gave me when I tried to load: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>
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>
![]()
here in scripts foldermariobrigade2018 wrote: ↑Wed Oct 23, 2024 4:19 pmWhere is minHUD located?andrei312g wrote: ↑Wed Oct 23, 2024 2:51 pmI only typed this for minHUD. I don't know what's missing.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.
![]()
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.andrei312g wrote: ↑Thu Oct 24, 2024 9:36 amhere in scripts foldermariobrigade2018 wrote: ↑Wed Oct 23, 2024 4:19 pmWhere is minHUD located?andrei312g wrote: ↑Wed Oct 23, 2024 2:51 pm
I only typed this for minHUD. I don't know what's missing.
![]()
![]()