Attract-Mode Support > Scripting
Sound on Button Push
FrizzleFried:
How do I code in sound on a certain button push?
I "hacked" this code from another layout to make a sound when moving from ROM to ROM, but I'd like to assign a sound to CUSTOM 1.
keilmillerjr:
Add a signal handler, check for custom1, then play custom sound. At work so hope this is enough to get you going.
https://github.com/mickelson/attract/blob/master/Layouts.md#add_signal_handler
https://github.com/mickelson/attract/blob/master/Layouts.md#add_sound
FrizzleFried:
Yeah... I'm failing miserably at trying to get this to work... considering I know next to nothing about coding, it's no surprise, but I've tried a few things with no success.
The current WORKING code that I hacked from another front end that makes the "click" sound when you move from ROM to ROM is:
--- Code: ---//game select sound
function select_sound( ttype, var, ttime ) {
switch ( ttype ) {
case Transition.ToNewSelection:
local sound = fe.add_sound("game.mp3");
sound.playing=true;
break;
}
return false;
}
fe.add_transition_callback( "select_sound" );
--- End code ---
I tried using that code and hacking in what I THOUGHT was possibly going to work... it didn't...
--- Code: ---function button_sound( ttype, var, ttime ) {
if ((signal_str=="custom1"))
{ local sound = fe.add_sound("game.mp3");
sound.playing=true;
break;
}
return false;
}
fe.add_transition_callback( "button_sound" );
--- End code ---
But again, being that I really have no idea what I am doing, it's no surprise it didn't work... but I figured I could at least TRY.
:D
NOW... anyone care to tell me what kind of a dummy I am and show me where I went wrong?
:)
calle81:
I think what you do might trigger Transition.ToNewList:
////////////////
//Sound effects
////////////
function fade_transitions( ttype, var, ttime ) {
switch ( ttype ) {
case Transition.ToNewSelection:
local Wheelclick = fe.add_sound("Click.mp3")
Wheelclick.playing=true
break;
case Transition.ToGame:
case Transition.ToNewList:
local Wheelclick = fe.add_sound("selection.mp3")
Wheelclick.playing=true
break;
}
return false;
}
calle81:
Otherwise this should work:
fe.add_signal_handler(this, "on_signalinfo");
function on_signalinfo(signal) {
if ( signal == "custom1" ){
local Wheelclick = fe.add_sound("selection.mp3")
Wheelclick.playing=true
return true;
}
return false;
}
Navigation
[0] Message Index
[#] Next page
Go to full version