Attract-Mode Support Forum
Attract-Mode Support => Scripting => Topic started by: wrybread on November 16, 2017, 05:29:31 PM
-
I'm trying to play a different sound when I switch selected ROM, switch display and start a ROM. All works well with the below code except starting a ROM. Is the transition not "ToGame"?
function fade_transitions( ttype, var, ttime ) {
switch ( ttype ) {
case Transition.ToNewList:
local Wheelclick = fe.add_sound("sounds/teleport.wav")
Wheelclick.playing=true
return false;
break;
}
switch ( ttype ) {
case Transition.ToGame:
local Wheelclick = fe.add_sound("sounds/boom.wav")
Wheelclick.playing=true
break;
}
switch ( ttype ) {
case Transition.ToNewSelection:
;case Transition.ToNewList:
local Wheelclick = fe.add_sound("sounds/clicked.wav")
Wheelclick.playing=true
break;
}
return false;
}
fe.add_transition_callback( "fade_transitions" );
-
it;s because entering a rom is not a wheelclick...
this should work for you. just change the sound file name, but i think you know that.
function togame( ttype, var, ttime ) {
switch ( ttype ) {
case Transition.ToGame:
local sound = fe.add_sound("intro.mp3");
sound.playing=true;
break;
}
return false;
}
fe.add_transition_callback( "togame" );
-
You can use one switch with multiple case statements as well, to clean up your code and DRY (don't repeat yourself).
-
Thanks for the tip on cleaning up the switch statement. I think this is a better way to write it, but I'm still not sure I understand the "break" statements, and whether I need one in each case:
function fade_transitions( ttype, var, ttime ) {
switch ( ttype ) {
case Transition.ToGame:
local sound = fe.add_sound("sounds/Burgertime_Dies.wav");
sound.playing=true;
break;
case Transition.ToNewList:
local Wheelclick = fe.add_sound("sounds/Asteroids_Tone02.wav");
Wheelclick.playing=true;
break;
case Transition.ToNewSelection:
local Wheelclick = fe.add_sound("sounds/clicked.wav");
Wheelclick.playing=true;
break;
}
return false;
}
fe.add_transition_callback( "fade_transitions" );
But still no joy.
And substituting the whole block for the code that @jedione posted also doesn't work for me.
Any idea why?
-
It works if I change the transition to FromGame (it then plays the sound when I return from the game), so I'm wondering if it's just not giving the sound enough time to play?
Can someone confirm that playing sounds with ToGame works?
-
It works if I change the transition to FromGame (it then plays the sound when I return from the game), so I'm wondering if it's just not giving the sound enough time to play?
Can someone confirm that playing sounds with ToGame works?
You need to wait until your sound is finished playing before returning the transition function. Look at my FadeToGame plugin. Maybe it help.
-
not shure why it dont work for you, this is what i get with the
same code that i posted....
preview...https://youtu.be/gJMP5VHeAM8 (https://youtu.be/gJMP5VHeAM8)
so i would say ToGame is working.
-
Thanks for the tip on cleaning up the switch statement. I think this is a better way to write it, but I'm still not sure I understand the "break" statements, and whether I need one in each case
"break" marks the end of each case. Without it, the code would continue on and execute the next case even if it wasn't a match. Similar to the closing } on an if statement.