If i just look at your question, and not your sample code I whould say you could set a variable called last_sprite_index to the current sprite_index Inside your create event.
You create event whould look like this:
Code:
last_sprite_index=sprite_index
Now inside the step event we can check the if the current sprite index has changes from the one we stored inside the create event. When we do this we will have to "reset" the last_sprite_index variable again else the sounds will play over each other.
Your step event would look like:
Code:
//the !() means that we want to execute this code when our statement is NOT true.
if !(last_sprite_index=sprite_index) then{
audio_play_sound (sound_buzzer,1,false);
last_sprite_index=sprite_index;//reset variable
}
Then if i look at the code you just send, i'd say why not just put audio_play_sound inside the brackets{} of where you are doing your keyboard_checks?
Like this:
Code:
if keyboard_check (vk_numpad1){
sprite_index = spr_x;
audio_play_sound (sound_buzzer,1,false);}
if keyboard_check (vk_numpad4){
sprite_index = spr_x;
audio_play_sound (sound_buzzer,1,false);}
If you want one "central" function, you could easily change, you could create a new script, or use a variable for that like this:
Code:
var playsound=false;
if keyboard_check (vk_numpad1){
sprite_index = spr_x;
playsound=true;
}
if keyboard_check (vk_numpad4){
sprite_index = spr_x;
playsound=true;
}
if playsound=true then{
audio_play_sound (sound_buzzer,1,false);}