2014-11-13 15:57:33

Hi all,
Okay, so now I'm wondering if I should put all my functions like keyboard practice etc into separate includes for easier management, but I know there's one brace I have to remove in this code. I fixed the while loop for exit now adding a left brace, but somewhere there's a brace that must be removed and I can't figure out which one.
Here is my code, again. Is it regarding the code that I just recently added for speech manager? I suppose I'll save the file under a different name and remove different braces although that wouldn't do me any good and only would mess me up even more.

#include "dynamic_menu.bgt"
#include "speech_manager.bgt"
//Sounds

sound music; //The music sound.
sound error_sound; // The sound for an incorrect sequence.
sound[] tone(4); // The four sequence tone sounds.
speech_manager speech; //The global variable to call the speech manager methods from.
void main()

{
speech.init("Config.dat", "310021561");

tone[0].load("sounds/1.wav");
tone[0].volume = -10;
tone[1].load("sounds/2.wav");
tone[1].volume = -10;
tone[2].load("sounds/3.wav");
tone[2].volume = -10;
tone[3].load("sounds/4.wav");
tone[3].volume = -10;

// Load error sound.
error_sound.load("sounds/error.wav");

tts_voice v;

show_game_window("Memory Train Deluxe");

dynamic_menu menu;
menu.set_speech_mode(speech.mode);
menu.set_tts_object(speech.sapi);

menu.add_item_tts("Start Game");
menu.add_item_tts("Keyboard Practice");
menu.add_item_tts("Speech Options");
menu.add_item_tts("Exit Game");

int choice; //This variable stores the players choice for menu options.
do
{

music.stream("sounds/music/menu.ogg");
music.volume=-10;
music.play_looped();

speech.speak_wait("Welcome to Memory Train Deluxe!");

choice = menu.run("Use the arrow keys to navigate the menu, enter to activate an option.", true);

if(choice==1)
{
music.stream("sounds/music/" + random(1, 30) + ".ogg");
music.volume=-10;
music.play_looped();
play_round();
}

else if(choice==2)
{
music.stream("sounds/music/" + random(1, 30) + ".ogg");
music.volume=-10;
music.play_looped();
keyboard_practice();
}

else if(choice==3)
{
speech.configure();
}

{
while(choice!=0 and choice!=4);
speech.speak_wait("See ya later!");
}

void keyboard_practice()
{
tts_voice v;
speech.speak_wait("Press any arrow key to find out which tone it is associated with.");
speech.speak_wait("Press Escape to exit keyboard practice.");
while(!key_pressed(KEY_ESCAPE))
{
if(key_pressed(KEY_LEFT))
{
play_tone(0);
}
else if(key_pressed(KEY_DOWN))
{
play_tone(1);
}
else if(key_pressed(KEY_RIGHT))
{
play_tone(2);
}

else if(key_pressed(KEY_UP))
{
play_tone(3);
}
wait(5);
}

}


void play_tone(int i)

{
tone[i].stop();
tone[i].play();
}

void play_round()
{
bool game_over = false; //Game will progressively get harder if this remains false.
int[] sequence; //The running sequence of tones to remember sequencially.
int seqlength = 0;
float tbt = 500; // The speed at which tones are played after one another.
float tbi = 2000; //Gives the player two seconds to choose a tone from a sequence.

do
{
seqlength++;
sequence.resize(seqlength);
sequence[seqlength-1] = random(0,3);
output_sequence(@sequence, tbt);
game_over = input_sequence(@sequence, tbi);
if((seqlength%5) == 0)
{
tbi = tbi*0.9;
if(tbi < 150)
{
tbi = 150;
}
}
}
while(!game_over);
int score = seqlength-1;
tts_voice v;
speech.speak_wait("Your final score is " + score);
}

void output_sequence(int[]@ sequence, float tbi)
{
timer clock;
int current;
for(uint i=0; i<sequence.length(); i++)
{
if(i>0)
{
clock.restart();
while(clock.elapsed < tbi)
{
wait(5);
}
}

current = sequence[i];
play_tone(current);

while(tone[current].playing)

{
wait(5);
}
}

bool input_sequence(int[] @sequence, float tbi)
{
timer clock;
for(uint i=0; i<sequence.length(); i++)
{
clock.restart();
int input = -1; // Set it to something invalid.
while(clock.elapsed < tbi)
{
if(key_pressed(KEY_LEFT))
{
input = 0;
}
else if(key_pressed(KEY_DOWN))
{
input = 1;
}
else if(key_pressed(KEY_RIGHT))
{
input = 2;
}
else if(key_pressed(KEY_UP))
{
input = 3;
}
if(input>=0)
{
break; // Stop waiting because something was typed.
}
wait(5);
}

if(input!=sequence[i])
{
error_sound.play_wait();
return true;
}

play_tone(input);
}

clock.restart();
while(clock.elapsed < 1000)
{
wait(5);
}

return false;

}
}

2014-11-13 16:07:23 (edited by stewie 2014-11-13 16:09:47)

The first issue I can see is:

else if(choice==3)
{
speech.configure();
}
//This should be an else statement.
{
while(choice!=0 and choice!=4);
/*This line of code will do nothing whatsoever. A while loop executes the code within it's block, IE enclosed within the braces. This loop will also execute if the loop is not equal to 0 or if the loop does not equal 4. This will trigger for the other menu choices. A while loop is a loop that executes when a given condition is true. An if statement does the same thing, but doesn't repeat. If you execute this loop, the speak_wait line will be repeated infinitely.*/
speech.speak_wait("See ya later!");
}
//You do not have enough closing braces, the program doesn't see the end of the main function.

Later on in the code you have similar:
while(!game_over);
This will not lead to a while loop.

Deep in the human unconscious is a pervasive need for a logical universe that makes sense. But the real universe is always one step beyond logic.

2014-11-13 17:53:38

Sorry if this is off topic, but does bgt support switch statements?

2014-11-13 19:26:24

Yes it does.

Official server host for vgstorm.com and developer of the Manamon 2 netplay server.
PSA: sending unsolicited PMs or emails to people you don't know asking them to buy you stuff is disrespectful. You'll just be ignored, so don't waste your time.

2014-11-14 00:52:46 (edited by camlorn 2014-11-14 00:57:37)

I'm pretty sure the left brace before the while is actually supposed to be a right brace, ending the do.  I didn't read the whole thing because that's the first really obvious error, and you're only mentioning one.
Edit: Also, looks like there's an extra right brace after keyboard_practice.  Your life will be orders of magnitude easier if you break this up--I, for one, cannot parse it as a unit, especially since there is no indentation.  Adding indentation after you find one of these errors may in fact be a good debugging technique for it, too.

My Blog
Twitter: @ajhicks1992

2014-11-14 03:05:49

Does putting it through this help?
http://dl.dropbox.com/u/16520690/matcher.bgt
I'd copy it into another file and cut blocks to approximate binary search. It's saved loads of time and frustration for me.
(I haven't had to do this much at all since I started indenting properly, though.)

Victorious wrote:

Sorry if this is off topic, but does bgt support switch statements?

Yes, but only for numeric constants. That's probably all you'd use them for anyway, but it is worth noting that I never could get them to work with chars.

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.