Post here for help and support regarding LunaLua and SMBX2's libraries and features.
Moderator: Userbase Moderators
|
|
|
|
-
Arco
- Koopa

- Posts: 17
- Joined: Mon Nov 08, 2021 9:32 pm
- Flair: Creative
- Pronouns: she/her
-
Contact:
Postby Arco » Mon Nov 08, 2021 9:47 pm
I am working on a concept level in which ends with a boss fight with a Big Boo. I am brand new to LunaLua, heck, even new to Lua, but I whipped up the following code to try to summon a "? Ball" NPC when my Big Boo boss dies;
Code: Select all boo = 1
function onLoadSection1()
boo = NPC.get(44, 1)
end
function onTick()
while( boo == 1 )
do
boo = NPC.get(44, 1)
if( boo == 0 )
then
NPC.spawn(16, -155232, 160256, 1)
break
else
boo = NPC.get(44, 1)
end
end
end
I tried to use the NPC.get function to set variable 'boo' to the amount of big boos exist, which is one, and when that one dies, I have the IF statement summon the ? Ball with NPC.spawn. I am in section 2. Could someone please help me, currently there is no output, no errors and no results.
|
|
|
|
|
|
|
|
|
-
DrMekar
- Eerie

- Posts: 781
- Joined: Sat Apr 08, 2017 7:16 am
- Flair: CUSTOM CHARACTER CREATOR
-
Contact:
Postby DrMekar » Tue Nov 09, 2021 8:43 am
Not gonna be nitpicky, but why do you use Luna Lua for this? You can just do this with SMBX Events.
|
|
|
|
|
|
|
|
|
-
deice
- Volcano Lotus

- Posts: 596
- Joined: Fri Jul 23, 2021 7:35 am
Postby deice » Tue Nov 09, 2021 10:10 am
Arco wrote: ↑Mon Nov 08, 2021 9:47 pm
I am working on a concept level in which ends with a boss fight with a Big Boo. I am brand new to LunaLua, heck, even new to Lua, but I whipped up the following code to try to summon a "? Ball" NPC when my Big Boo boss dies;
Code: Select all boo = 1
function onLoadSection1()
boo = NPC.get(44, 1)
end
function onTick()
while( boo == 1 )
do
boo = NPC.get(44, 1)
if( boo == 0 )
then
NPC.spawn(16, -155232, 160256, 1)
break
else
boo = NPC.get(44, 1)
end
end
end
I tried to use the NPC.get function to set variable 'boo' to the amount of big boos exist, which is one, and when that one dies, I have the IF statement summon the ? Ball with NPC.spawn. I am in section 2. Could someone please help me, currently there is no output, no errors and no results.
NPC.get() returns a table of NPCs. trying to compare that with a number will always yield false, and thus the loop will never execute. if you want to try checking whether or not an NPC is valid, do something like
instead of
and vice-versa (of course, this is assuming there can only be one big boo present at one time in the section)
though strictly speaking, i think that you'd want to refactor the code in general because if the boo isn't immediately dead when the loop begins to execute, it will never reach it's exit condition and will lock your game up.
|
|
|
|
|
|
|
|
|
-
Arco
- Koopa

- Posts: 17
- Joined: Mon Nov 08, 2021 9:32 pm
- Flair: Creative
- Pronouns: she/her
-
Contact:
Postby Arco » Wed Nov 10, 2021 2:25 am
deice wrote: ↑Tue Nov 09, 2021 10:10 am
Arco wrote: ↑Mon Nov 08, 2021 9:47 pm
I am working on a concept level in which ends with a boss fight with a Big Boo. I am brand new to LunaLua, heck, even new to Lua, but I whipped up the following code to try to summon a "? Ball" NPC when my Big Boo boss dies;
Code: Select all boo = 1
function onLoadSection1()
boo = NPC.get(44, 1)
end
function onTick()
while( boo == 1 )
do
boo = NPC.get(44, 1)
if( boo == 0 )
then
NPC.spawn(16, -155232, 160256, 1)
break
else
boo = NPC.get(44, 1)
end
end
end
I tried to use the NPC.get function to set variable 'boo' to the amount of big boos exist, which is one, and when that one dies, I have the IF statement summon the ? Ball with NPC.spawn. I am in section 2. Could someone please help me, currently there is no output, no errors and no results.
NPC.get() returns a table of NPCs. trying to compare that with a number will always yield false, and thus the loop will never execute. if you want to try checking whether or not an NPC is valid, do something like
instead of
and vice-versa (of course, this is assuming there can only be one big boo present at one time in the section)
though strictly speaking, i think that you'd want to refactor the code in general because if the boo isn't immediately dead when the loop begins to execute, it will never reach it's exit condition and will lock your game up.
How would I do that?
|
|
|
|
|
|
|
|
|
-
Emral
- Cute Yoshi Egg

- Posts: 9865
- Joined: Mon Jan 20, 2014 12:58 pm
- Flair: Phoenix
Postby Emral » Wed Nov 10, 2021 5:38 am
deice wrote: ↑Tue Nov 09, 2021 10:10 am
NPC.get() returns a table of NPCs. trying to compare that with a number will always yield false, and thus the loop will never execute. if you want to try checking whether or not an NPC is valid, do something like
instead of
and vice-versa (of course, this is assuming there can only be one big boo present at one time in the section)
though strictly speaking, i think that you'd want to refactor the code in general because if the boo isn't immediately dead when the loop begins to execute, it will never reach it's exit condition and will lock your game up.
Using a while loop for this is indeed not a good way. This is in onTick, so all you'd accomplish is a hard lock, since this code will never finish while in the while loop.
While it's true that "boo" is a list of NPCs, and thus cannot be compared with a number, "#boo" IS the number of boos in that list, so...
Code: Select all local hasSpawnedExit = false
function onTick()
if not hasSpawnedExit then
local boo = NPC.get(44, 1)
if #boo == 0 then
NPC.spawn(16, -155232, 160256, 1)
hasSpawnedExit = true
end
end
end
This conditional executes when no boos were found by the NPC.get.
|
|
|
|
|
|
|
|
|
-
Arco
- Koopa

- Posts: 17
- Joined: Mon Nov 08, 2021 9:32 pm
- Flair: Creative
- Pronouns: she/her
-
Contact:
Postby Arco » Fri Mar 11, 2022 7:30 pm
DrMekar wrote: ↑Tue Nov 09, 2021 8:43 am
Not gonna be nitpicky, but why do you use Luna Lua for this? You can just do this with SMBX Events.
I don't know how to do that either
|
|
|
|
|
|
|
|
|
-
DrMekar
- Eerie

- Posts: 781
- Joined: Sat Apr 08, 2017 7:16 am
- Flair: CUSTOM CHARACTER CREATOR
-
Contact:
Postby DrMekar » Wed Mar 16, 2022 3:45 pm
Arco wrote: ↑Fri Mar 11, 2022 7:30 pm
DrMekar wrote: ↑Tue Nov 09, 2021 8:43 am
Not gonna be nitpicky, but why do you use Luna Lua for this? You can just do this with SMBX Events.
I don't know how to do that either
You select the Boss and open the NPC Settings. There you select an Event, you created before in 'Events', that
gets triggered when the NPC dies.
|
|
|
|
|
Return to “LunaLua Help”
Users browsing this forum: No registered users and 1 guest
|