Need help with lua? - LunaLua General Help

This is the place for discussion and support for LunaLua and related modifications and libraries.
Forum rules
Before you make a topic/post, consider the following:
-Is there a topic for this already?
-Is your post on topic/appropriate?
-Are you posting in the right forum/following the forum rules?
User avatar
Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 7708
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: Need help with lua? - LunaLua General Help

Postby Enjl » Sat Jan 28, 2017 8:56 pm

timocomsmbx2345 wrote:I loaded the custom lotus file and i have a npcdata.json file, and when i typed in "palm tree" literally nothing happened.
viewtopic.php?f=87&t=13826
ImageImageImageImage
ImageImageImageImageImageImage

User avatar
timocomsmbx2345
Ninji
Ninji
Posts: 825
Joined: Sat Feb 06, 2016 1:44 pm
Current Project: i dont even know anymore. . . .
Chat Username: same as my username
Contact:

Re: Need help with lua? - LunaLua General Help

Postby timocomsmbx2345 » Sat Jan 28, 2017 8:57 pm

Hoeloe wrote:The "corrupted" thing clearly comes from the download stopping early, meaning you only have half the file (hence the "unexpected end of file" error). Why it's doing that I'm not sure, but since you are the only person to have this issue, I'm pretty sure it's not the file that is the problem.
I'm having that issue too when i was downloading an episode. . . . .
SMBX 2.0 β4 is here!!! How about 2.0 β5?
ImageImage
Image
Meepyglobix wrote:DON'T SAY "38A??". OR I'll SHOOT YOU.
Spoiler: show
Image Thanks Pixelpest!!!!
Image
Image

User avatar
DeMuZ
Bob-omb
Bob-omb
Posts: 37
Joined: Thu Aug 18, 2016 2:35 pm
Current Project: The Episode of Nonsense series

Re: Need help with lua? - LunaLua General Help

Postby DeMuZ » Sun Jan 29, 2017 9:43 am

Is there any way to respawn (only) killed npcs?

User avatar
Phazon1111
Rex
Rex
Posts: 81
Joined: Fri Dec 27, 2013 5:24 pm

Re: Need help with lua? - LunaLua General Help

Postby Phazon1111 » Mon Feb 06, 2017 7:00 pm

I'm trying to make it that when NPC 178 (The SMB1 axe) is collected, 30 seconds is added to the level's timer in similar fashion to the speed run levels from SMG2/SM3DL/SM3DW
via leveltimer.lua.

Code: Select all

timerApi = loadAPI("leveltimer");

function onLoad()  
	--But now in the onLoad override, we set a few values
	timerApi.setSecondsLeft(30);
 --For one, we need to set the timer value. No greater than 999
	timerApi.setTimerState(true);
 --Then, we need to make sure we enable it. It's not enabled by default
end


function onNPCKill(eventObj,npcID,killReason)
	if npcID == 178 then
		getSecondsLeft()
		timerApi.setSecondsLeft(timerApi.secondsleft + 10)
	end
end
No error messages pop up upon starting the level or collect the axe.
Spoiler: show
Image

User avatar
Natsu
Wart
Wart
Posts: 3011
Joined: Sat Dec 21, 2013 2:40 pm
Current Project: It's a secret to everybody ...
Chat Username: Kuma-san

Re: Need help with lua? - LunaLua General Help

Postby Natsu » Mon Feb 06, 2017 10:41 pm

Is that all the code there is? There is no "getSecondsLeft" function anywhere in there. We also don't know what is it that you get. Does it not increase? Does the increased amount not match what you want (which judging by the code you posted seems to be the case, it's increasing 10 and not 30)?
Discord quotes
Trace: You're a capable boi

User avatar
Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 7708
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: Need help with lua? - LunaLua General Help

Postby Enjl » Tue Feb 07, 2017 12:47 am

Phazon1111 wrote:I'm trying to make it that when NPC 178 (The SMB1 axe) is collected, 30 seconds is added to the level's timer in similar fashion to the speed run levels from SMG2/SM3DL/SM3DW
via leveltimer.lua.

Code: Select all

timerApi = loadAPI("leveltimer");

function onLoad()  
	--But now in the onLoad override, we set a few values
	timerApi.setSecondsLeft(30);
 --For one, we need to set the timer value. No greater than 999
	timerApi.setTimerState(true);
 --Then, we need to make sure we enable it. It's not enabled by default
end


function onNPCKill(eventObj,npcID,killReason)
	if npcID == 178 then
		getSecondsLeft()
		timerApi.setSecondsLeft(timerApi.secondsleft + 10)
	end
end
No error messages pop up upon starting the level or collect the axe.
Many things wrong:
-getSecondsLeft is a function from leveltimer so you have to prefix it with timerApi. like you did for the others
-npcID is a misnomer because the variable contains the killed npc. I prefer to call it killedNPC. You can cet the ID with killedNPC.id (or right now npcID.id which is silly)
-you should seriously use onStart in favour of onLoop. The latter has been deprecated for over a year.
-you sould make the timerApi variable local so only this file can access it.
-loadAPI has been deprecated for over a year and replaced with API.load. Use that.
ImageImageImageImage
ImageImageImageImageImageImage

User avatar
Phazon1111
Rex
Rex
Posts: 81
Joined: Fri Dec 27, 2013 5:24 pm

Re: Need help with lua? - LunaLua General Help

Postby Phazon1111 » Tue Feb 07, 2017 4:24 pm

Intuition wrote:Is that all the code there is? There is no "getSecondsLeft" function anywhere in there. We also don't know what is it that you get. Does it not increase? Does the increased amount not match what you want (which judging by the code you posted seems to be the case, it's increasing 10 and not 30)?
Oh, whoops. I meant to write 10 seconds on my post.
The problem is that it's not increasing.
Enjl wrote:
Phazon1111 wrote:I'm trying to make it that when NPC 178 (The SMB1 axe) is collected, 30 seconds is added to the level's timer in similar fashion to the speed run levels from SMG2/SM3DL/SM3DW
via leveltimer.lua.

Code: Select all

timerApi = loadAPI("leveltimer");

function onLoad()  
	--But now in the onLoad override, we set a few values
	timerApi.setSecondsLeft(30);
 --For one, we need to set the timer value. No greater than 999
	timerApi.setTimerState(true);
 --Then, we need to make sure we enable it. It's not enabled by default
end


function onNPCKill(eventObj,npcID,killReason)
	if npcID == 178 then
		getSecondsLeft()
		timerApi.setSecondsLeft(timerApi.secondsleft + 10)
	end
end
No error messages pop up upon starting the level or collect the axe.
Many things wrong:
-getSecondsLeft is a function from leveltimer so you have to prefix it with timerApi. like you did for the others
-npcID is a misnomer because the variable contains the killed npc. I prefer to call it killedNPC. You can cet the ID with killedNPC.id (or right now npcID.id which is silly)
-you should seriously use onStart in favour of onLoop. The latter has been deprecated for over a year.
-you sould make the timerApi variable local so only this file can access it.
-loadAPI has been deprecated for over a year and replaced with API.load. Use that.
When your sources are outdated. :(
Also, where do I put the "killedNPC.id" part?
Spoiler: show
Image

User avatar
Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 7708
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: Need help with lua? - LunaLua General Help

Postby Enjl » Tue Feb 07, 2017 4:28 pm

npcID should be killedNPC. killedNPC is an object of type NPC. You use killedNPC.id where you want to get the id of the killed npc.
ImageImageImageImage
ImageImageImageImageImageImage

User avatar
Phazon1111
Rex
Rex
Posts: 81
Joined: Fri Dec 27, 2013 5:24 pm

Re: Need help with lua? - LunaLua General Help

Postby Phazon1111 » Tue Feb 07, 2017 4:35 pm

OK, so now this happens when the axe is collected.
Image
Spoiler: show
Image

User avatar
Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 7708
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: Need help with lua? - LunaLua General Help

Postby Enjl » Tue Feb 07, 2017 4:36 pm

timerApi.secondsLeft doesn't exist. Double-check the spelling in your code.
ImageImageImageImage
ImageImageImageImageImageImage

User avatar
Phazon1111
Rex
Rex
Posts: 81
Joined: Fri Dec 27, 2013 5:24 pm

Re: Need help with lua? - LunaLua General Help

Postby Phazon1111 » Tue Feb 07, 2017 6:53 pm

I think I might have found the problem.
Image
I'm just not sure how to solve it.
Spoiler: show
Image

User avatar
PixelPest
Link
Link
Posts: 7118
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Current Project: Boom Boom Evolution
Chat Username: PixelPest
Contact:

Re: Need help with lua? - LunaLua General Help

Postby PixelPest » Tue Feb 07, 2017 7:03 pm

There's a function as a part of leveltimer.lua which returns that variable:

Code: Select all

function lf_levelTimerApi.getSecondsLeft()
   return secondsleft;
end
Also remember that onNPCKill() does not return the killed NPC's ID, but the object itself. (See the documentation.)

Therefore, you need to do something like:

Code: Select all

function onNPCKill(_, killedNPC, _)
   if killedNPC.id == 178 then
      timerApi.setSecondsLeft(timerApi.getSecondsLeft() + 10);
   end
end

User avatar
Phazon1111
Rex
Rex
Posts: 81
Joined: Fri Dec 27, 2013 5:24 pm

Re: Need help with lua? - LunaLua General Help

Postby Phazon1111 » Tue Feb 07, 2017 7:19 pm

Current Code:

Code: Select all

local timerApi = API.load("leveltimer");

function onStart()  
	--But now in the onLoad override, we set a few values
	timerApi.setSecondsLeft(30);
 --For one, we need to set the timer value. No greater than 999
	timerApi.setTimerState(true);
 --Then, we need to make sure we enable it. It's not enabled by default
end

function onNPCKill(_, killedNPC, _)
   if killedNPC.id == 178 then
      timerApi.setSecondsLeft(timerApi.getSecondsLeft() + 10);
   end
end
It's not crashing anymore, but it adds 10 seconds onto the starting time (30 seconds) rather than time the axe is collected.
Spoiler: show
Image

User avatar
Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 7708
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: Need help with lua? - LunaLua General Help

Postby Enjl » Tue Feb 07, 2017 7:22 pm

It appears that secondsLeft is never updated outside the setSecondsLeft function.
ImageImageImageImage
ImageImageImageImageImageImage

User avatar
Angelus
Bit
Bit
Posts: 129
Joined: Tue Jun 21, 2016 9:38 am

Re: Need help with lua? - LunaLua General Help

Postby Angelus » Fri Feb 10, 2017 4:25 pm

Does anyone know the exact jump height of Toad? If not, can someone tell me how to find it out?

User avatar
Mosaic
Ludwig von Koopa
Ludwig von Koopa
Posts: 2826
Joined: Fri Feb 27, 2015 8:07 pm
Current Project: The Mosaic Group's Journey, Toad's SMB Adventure, Mosaic Adventures and Other Secret Projects?
Chat Username: Mosaic
Contact:

Re: Need help with lua? - LunaLua General Help

Postby Mosaic » Tue Feb 14, 2017 1:08 am

How do i make a string of text with a lua code? I'm putting in this
code:

Code: Select all

function onMessageBox(eventObj, msgStr)
   if msgStr = "CutsceneTalk1" then
      eventObj.cancelled == true
		Text.showMessageBox("MosaicMario: Great job guys! We made it through the fortress!")
		Text.showMessageBox("Rosy: I wonder why there were so many ninjis in there?")
	end
end

function onMessageBox(eventObj, msgStr)
   if msgStr = "CutsceneTalk2" then
      eventObj.cancelled == true
		Text.showMessageBox("Hoops: Hey guys, look at this bridge! Where could it lead?")
		Text.showMessageBox("Berry: Yoshi!(I don't know, but i'm curious too!)")
		Text.showMessageBox("MosaicMario: Hoops, I think that maybe you should slow dow-")
		Text.showMessageBox("Hoops: Last one to the other side's a rotton mushroom!")
   end
end

function onMessageBox(eventObj, msgStr)
	if msgStr = "CutsceneTalk3" then
	   eventObj.cancelled == true
		Text.showMessageBox("MosaicMario: Hoops! Wait up!")
   end
end

function onMessageBox(eventObj, msgStr)
   if msgStr = "CutsceneTalk4" then
      eventObj.cancelled == true
		Text.showMessageBox("Rosy:...Well, what do you say Berry? Should we catch up with them?")
		Text.showMessageBox("Berry: Yoshi!(Yeah, sure!)")
		Text.showMessageBox("Rosy: Let's go catch them i guess.")
   end
end	
But it won't work, what do i do about this?
While your at it, how do you set a boss's health?

I believe in Jesus Christ as my Lord and Savior. If you do, put this in your signature.
And Here's The Proof
My Rainbow Of Levels
Mosaic's Museum(My Discord)

Image

Image

Danny wrote:Here's some constructive criticism: What the hell.
Witchking wrote:Approved!

Discord Quotes: show
Image


User avatar
Hoeloe
Grinder
Grinder
Posts: 1067
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Current Project: A2XT Episode 2

Re: Need help with lua? - LunaLua General Help

Postby Hoeloe » Tue Feb 14, 2017 2:39 am

MosaicMario wrote:

Code: Select all

function onMessageBox(eventObj, msgStr)
   if msgStr = "CutsceneTalk1" then

function onMessageBox(eventObj, msgStr)
   if msgStr = "CutsceneTalk2" then
   
function onMessageBox(eventObj, msgStr)
	if msgStr = "CutsceneTalk3" then

function onMessageBox(eventObj, msgStr)
   if msgStr = "CutsceneTalk4" then	

Quick question:

When you display a message box, how do you think the code determines which of these it has to run? It can't be that if statement, because that only occurs after it's already started to run the function.

Basically, you can't have multiple definitions of the same function. You should be using elseif statements rather than trying to redefine the function.

User avatar
Mosaic
Ludwig von Koopa
Ludwig von Koopa
Posts: 2826
Joined: Fri Feb 27, 2015 8:07 pm
Current Project: The Mosaic Group's Journey, Toad's SMB Adventure, Mosaic Adventures and Other Secret Projects?
Chat Username: Mosaic
Contact:

Re: Need help with lua? - LunaLua General Help

Postby Mosaic » Tue Feb 14, 2017 9:17 pm

Hoeloe wrote:
MosaicMario wrote:

Code: Select all

function onMessageBox(eventObj, msgStr)
   if msgStr = "CutsceneTalk1" then

function onMessageBox(eventObj, msgStr)
   if msgStr = "CutsceneTalk2" then
   
function onMessageBox(eventObj, msgStr)
	if msgStr = "CutsceneTalk3" then

function onMessageBox(eventObj, msgStr)
   if msgStr = "CutsceneTalk4" then	

Quick question:

When you display a message box, how do you think the code determines which of these it has to run? It can't be that if statement, because that only occurs after it's already started to run the function.

Basically, you can't have multiple definitions of the same function. You should be using elseif statements rather than trying to redefine the function.
So something like this?:

Code: Select all

function onMessageBox(eventObj, msgStr)
   if msgStr == "CutsceneTalk1" then
      eventObj.cancelled === true
      Text.showMessageBox("MosaicMario: Great job guys! We made it through the fortress!")
      Text.showMessageBox("Rosy: I wonder why there were so many ninjis in there?")
      elseif msgStr == "CutsceneTalk2" then
      eventObj.cancelled === true
      Text.showMessageBox("Hoops: Hey guys, look at this bridge! Where could it lead?")
      Text.showMessageBox("Berry: Yoshi!(I don't know, but i'm curious too!)")
      Text.showMessageBox("MosaicMario: Hoops, I think that maybe you should slow dow-")
      Text.showMessageBox("Hoops: Last one to the other side's a rotton mushroom!")
      elseif msgStr == "CutsceneTalk3" then
      eventObj.cancelled === true
      Text.showMessageBox("MosaicMario: Hoops! Wait up!")
      elseif msgStr == "CutsceneTalk4" then
      eventObj.cancelled === true
      Text.showMessageBox("Rosy:...Well, what do you say Berry? Should we catch up with them?")
      Text.showMessageBox("Berry: Yoshi!(Yeah, sure!)")
      Text.showMessageBox("Rosy: Let's go catch them i guess.")
   end
end   
I actually tried using this, but it still didn't work.

I believe in Jesus Christ as my Lord and Savior. If you do, put this in your signature.
And Here's The Proof
My Rainbow Of Levels
Mosaic's Museum(My Discord)

Image

Image

Danny wrote:Here's some constructive criticism: What the hell.
Witchking wrote:Approved!

Discord Quotes: show
Image


User avatar
PixelPest
Link
Link
Posts: 7118
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Current Project: Boom Boom Evolution
Chat Username: PixelPest
Contact:

Re: Need help with lua? - LunaLua General Help

Postby PixelPest » Tue Feb 14, 2017 10:05 pm

What in the world is === ? I'm pretty sure you got what Hoeloe was trying to get you to do though

User avatar
Mosaic
Ludwig von Koopa
Ludwig von Koopa
Posts: 2826
Joined: Fri Feb 27, 2015 8:07 pm
Current Project: The Mosaic Group's Journey, Toad's SMB Adventure, Mosaic Adventures and Other Secret Projects?
Chat Username: Mosaic
Contact:

Re: Need help with lua? - LunaLua General Help

Postby Mosaic » Tue Feb 14, 2017 10:17 pm

i removed the extra =, but it still doesn't work, what am i doing wrong?

I believe in Jesus Christ as my Lord and Savior. If you do, put this in your signature.
And Here's The Proof
My Rainbow Of Levels
Mosaic's Museum(My Discord)

Image

Image

Danny wrote:Here's some constructive criticism: What the hell.
Witchking wrote:Approved!

Discord Quotes: show
Image



Return to “LunaLua”

Who is online

Users browsing this forum: No registered users and 3 guests