Attract-Mode Support Forum

Attract-Mode Support => Scripting => Topic started by: FrizzleFried on February 15, 2018, 08:55:21 AM

Title: Sound on Button Push
Post by: FrizzleFried on February 15, 2018, 08:55:21 AM
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.
Title: Re: Sound on Button Push
Post by: keilmillerjr on February 15, 2018, 09:40:01 AM
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
Title: Re: Sound on Button Push
Post by: FrizzleFried on February 16, 2018, 12:35:40 PM
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: [Select]
//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" );

I tried using that code and hacking in what I THOUGHT was possibly going to work... it didn't...

Code: [Select]
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" );

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? 

:)
Title: Re: Sound on Button Push
Post by: calle81 on February 17, 2018, 12:51:10 AM
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;
}
Title: Re: Sound on Button Push
Post by: calle81 on February 17, 2018, 01:07:21 AM
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;
}
Title: Re: Sound on Button Push
Post by: FrizzleFried on February 17, 2018, 12:59:15 PM
Using the 2nd code you posted (directly above)... I now get the click when I push CUSTOM1 (button)... unfortunately the animation (CUSTOM1 is associated with moving from the "LIST" screen to the "INFO" screen to the "FLYER" screen then to the "CABINET" screen and then back again.  Now it just... clicks.  :)

Is it perhaps WHERE I put the code that makes the difference?

THANK YOU!!

EDIT:
Figured it out.  All I needed to do was change the first "return true;" to "return false;"...

:)

Thanks!

EDIT: BUT... it broke the "movement" sound... I'll get it though.  :D

EDIT: Fixed... ;)

Title: Re: Sound on Button Push
Post by: calle81 on February 18, 2018, 01:29:00 AM
Happy it worked out for you :)