Page 46 of 76
Re: Need help with lua? - LunaLua General Help
Posted: Sat Jan 28, 2017 8:57 pm
by timocomsmbx2345
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. . . . .
Re: Need help with lua? - LunaLua General Help
Posted: Sun Jan 29, 2017 9:43 am
by DeMuZ
Is there any way to respawn (only) killed npcs?
Re: Need help with lua? - LunaLua General Help
Posted: Mon Feb 06, 2017 7:00 pm
by Phazon1111
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.
Re: Need help with lua? - LunaLua General Help
Posted: Mon Feb 06, 2017 10:41 pm
by Fuyu
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)?
Re: Need help with lua? - LunaLua General Help
Posted: Tue Feb 07, 2017 12:47 am
by Emral
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.
Re: Need help with lua? - LunaLua General Help
Posted: Tue Feb 07, 2017 4:24 pm
by Phazon1111
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?
Re: Need help with lua? - LunaLua General Help
Posted: Tue Feb 07, 2017 4:28 pm
by Emral
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.
Re: Need help with lua? - LunaLua General Help
Posted: Tue Feb 07, 2017 4:35 pm
by Phazon1111
OK, so now this happens when the axe is collected.

Re: Need help with lua? - LunaLua General Help
Posted: Tue Feb 07, 2017 4:36 pm
by Emral
timerApi.secondsLeft doesn't exist. Double-check the spelling in your code.
Re: Need help with lua? - LunaLua General Help
Posted: Tue Feb 07, 2017 6:53 pm
by Phazon1111
I think I might have found the problem.

I'm just not sure how to solve it.
Re: Need help with lua? - LunaLua General Help
Posted: Tue Feb 07, 2017 7:03 pm
by PixelPest
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
Re: Need help with lua? - LunaLua General Help
Posted: Tue Feb 07, 2017 7:19 pm
by Phazon1111
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.
Re: Need help with lua? - LunaLua General Help
Posted: Tue Feb 07, 2017 7:22 pm
by Emral
It appears that secondsLeft is never updated outside the setSecondsLeft function.
Re: Need help with lua? - LunaLua General Help
Posted: Fri Feb 10, 2017 4:25 pm
by Angelus
Does anyone know the exact jump height of Toad? If not, can someone tell me how to find it out?
Re: Need help with lua? - LunaLua General Help
Posted: Tue Feb 14, 2017 1:08 am
by PersonNamedUser
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?
Re: Need help with lua? - LunaLua General Help
Posted: Tue Feb 14, 2017 2:39 am
by Hoeloe
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.
Re: Need help with lua? - LunaLua General Help
Posted: Tue Feb 14, 2017 9:17 pm
by PersonNamedUser
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.
Re: Need help with lua? - LunaLua General Help
Posted: Tue Feb 14, 2017 10:05 pm
by PixelPest
What in the world is === ? I'm pretty sure you got what Hoeloe was trying to get you to do though
Re: Need help with lua? - LunaLua General Help
Posted: Tue Feb 14, 2017 10:17 pm
by PersonNamedUser
i removed the extra =, but it still doesn't work, what am i doing wrong?
Re: Need help with lua? - LunaLua General Help
Posted: Tue Feb 14, 2017 10:22 pm
by PixelPest
Post your code here again