Page 1 of 1

How to put custom sound effects and music lunalua problems

Posted: Wed Jul 31, 2024 7:11 pm
by Levelmaker_123
Alright,this may not be the last one but I really need help.
So first one is that the code that Just_Thomas provided is good and all and I'am pretty sure I screwed up again,but when I try to change custom music again (I just copied and pasted the code and changed the .mp 3 file) it shows this error
Original code:

Code: Select all

function onEvent(eventName)
	if(eventName == "musictrigger1") then
	Audio.MusicChange(0, "Wario Land Shake It! OST - Bad Manor.ogg", 200)
	end
end
Error code:

Code: Select all

	main.lua:717: in function '__newindex'
	...Base Part III/Invading The Shroob Base Part III/luna.lua:15: in function 'codeFile'
	main.lua:742: in function 'loadCodeFile'
	main.lua:892: in function <main.lua:792>
	[C]: in function '__xpcall'
	main.lua:792: in function <main.lua:791>
Yeah,so this lunalua is for a cutscene and I don't know of I can only paste this once per level or what...
So the second one simpler but I need a way to put custom sound effects in game.
I recently switched from smbx 1.4.5 and there was a menu to do that so I didn't need to mess with the files.
But of there is a menu in smbx 2 for sound effects I didn't found it. I don't know if renaming the file should do it,but yeah,these are the problems.

Re: How to put custom sound effects and music lunalua problems

Posted: Wed Jul 31, 2024 8:02 pm
by Emral
That error log is incomplete. Could you share the whole error window you get, as a screenshot?

Re: How to put custom sound effects and music lunalua problems

Posted: Thu Aug 01, 2024 4:33 am
by Levelmaker_123
Image

Re: How to put custom sound effects and music lunalua problems

Posted: Thu Aug 01, 2024 6:20 am
by Emral
Levekmaker_123 wrote:
Thu Aug 01, 2024 4:33 am
Image
Thank you!
The important bit in this one is the red text. It reads: "Overwritten handler onEvent in [path to your lua script]".
This means that you have 2 functions onEvent. This is a common mistake that can be easily fixed by moving the contents from one of the two into the other, then deleting the now-empty onEvent. Keep in mind that you can only have one function of each name in every script.

Re: How to put custom sound effects and music lunalua problems

Posted: Thu Aug 01, 2024 12:45 pm
by Levelmaker_123
Emral wrote:
Thu Aug 01, 2024 6:20 am
Levekmaker_123 wrote:
Thu Aug 01, 2024 4:33 am
Image
Thank you!
The important bit in this one is the red text. It reads: "Overwritten handler onEvent in [path to your lua script]".
This means that you have 2 functions onEvent. This is a common mistake that can be easily fixed by moving the contents from one of the two into the other, then deleting the now-empty onEvent. Keep in mind that you can only have one function of each name in every script.
I'am not too sure of I combined them correctly but here is what I did:

Code: Select all

function onEvent(eventName)
	if(eventName == "musictrigger1") then
	Audio.MusicChange(0, "Wario Land Shake It! OST - Bad Manor.ogg", 200)
	if(eventName == "musictrigger2") then
		Audio.MusicChange(0, "Wario Land Shake It! OST - Bad Manor.ogg", 200)
	end
end

Re: How to put custom sound effects and music lunalua problems

Posted: Thu Aug 01, 2024 6:10 pm
by Emral
Levekmaker_123 wrote:
Thu Aug 01, 2024 12:45 pm
Emral wrote:
Thu Aug 01, 2024 6:20 am
Levekmaker_123 wrote:
Thu Aug 01, 2024 4:33 am
Image
Thank you!
The important bit in this one is the red text. It reads: "Overwritten handler onEvent in [path to your lua script]".
This means that you have 2 functions onEvent. This is a common mistake that can be easily fixed by moving the contents from one of the two into the other, then deleting the now-empty onEvent. Keep in mind that you can only have one function of each name in every script.
I'am not too sure of I combined them correctly but here is what I did:

Code: Select all

function onEvent(eventName)
	if(eventName == "musictrigger1") then
	Audio.MusicChange(0, "Wario Land Shake It! OST - Bad Manor.ogg", 200)
	if(eventName == "musictrigger2") then
		Audio.MusicChange(0, "Wario Land Shake It! OST - Bad Manor.ogg", 200)
	end
end
Very close! Every "if" needs an "elseif" or an "end". Try this:

Code: Select all

function onEvent(eventName)
	if(eventName == "musictrigger1") then
		Audio.MusicChange(0, "Wario Land Shake It! OST - Bad Manor.ogg", 200)
	elseif(eventName == "musictrigger2") then
		Audio.MusicChange(0, "Wario Land Shake It! OST - Bad Manor.ogg", 200)
	end
end
Or this:

Code: Select all

function onEvent(eventName)
	if(eventName == "musictrigger1") then
		Audio.MusicChange(0, "Wario Land Shake It! OST - Bad Manor.ogg", 200)
	end
	if(eventName == "musictrigger2") then
		Audio.MusicChange(0, "Wario Land Shake It! OST - Bad Manor.ogg", 200)
	end
end
Either will do the trick. The difference is that in the top variant, the elseif will be automatically skipped if the if was correct.