Topic: My metronome test doesn't work, why?

Hi there,

I've tried to make a little metronome in bgt but it doesn't play the klick sound. Though the loop seems to bee entered so I can't understand what's wrong here, hope anyone can help me!

The code-Snippet is under the message.

Thanks in atvance!


timer klick;
sound klick_sound;
void main()
double bpm;
string bpm_string;
double klicktime;
show_game_window("Metronom Test");
bpm_string = input_box("bpm", "Bitte bpm eingeben:");
bpm = string_to_number(bpm_string);
klicktime = round((60/bpm*1000), 2);
//alert("Klicktime", klicktime);
//alert("", "In Schleife");

Re: My metronome test doesn't work, why?

just remove the first klick.restart(); line in the loop. Like this, it restarts the timer on every iteration without doing anything, so it never has a chance to actually reach the point where it should play the click sound.

Also, just for your info, you could easily remove the last three lines before the right brace that closes the main function. I mean the lines that stop the sound, close it and then tell the program to exit. These are not needed at all and it would perform the same thing anyway, since BGT exits automatically when it has nothing else to do by default, and cleanup like cleaning used sounds from memory is standard procedure then.

Finally, you need a wait call in your loop just to make sure your script doesn't keep using your CPU at 100% all the time. Just add this line to the very top or bottom of your loop, making sure it's actually inside it:
wait (5);

Hope this helps,