so here's my gameloop:
while(!key[KEY_ESC])
{
if(key[KEY_ENTER]){ PlaceBet();}
}
allegro_exit();
}
END_OF_MAIN();
and here's the function PlaceBet:
void PlaceBet()
{
//Clear text and redraw border
rectfill(buffer,0,140,WIDTH,HEIGHT,BGCOL);
rect(buffer, 0, 0, WIDTH-1, HEIGHT-11, YELLOW);
rect(buffer, 1, 1, WIDTH-2, HEIGHT-12, YELLOW);
textout_centre(buffer,maintext,"Press + and - on keypad to change by $10",WIDTH/2,150,TXTCOL);
textout_centre(buffer,maintext,"Press up and down arrows to change by $100",WIDTH/2,190,TXTCOL);
//clear_keybuf();
while(!key[KEY_ENTER])
{
if(key[KEY_PLUS_PAD]) {bet += 10;}
if(key[KEY_MINUS_PAD]) {bet -= 10;}
if(key[KEY_UP]) {bet += 100;}
if(key[KEY_DOWN]) {bet -= 100;}
if(bet<10) { bet = 10;}
if(bet>money) { bet = money;}
rectfill(buffer,0,300,WIDTH,HEIGHT,BGCOL);
rect(buffer, 0, 0, WIDTH-1, HEIGHT-11, YELLOW);
rect(buffer, 1, 1, WIDTH-2, HEIGHT-12, YELLOW);
textprintf_centre(buffer,maintext, 390,350,TXTCOL,"Money: $ %i",money);
textprintf_centre(buffer,maintext, 390,380,TXTCOL,"Bet: $ %i",bet);
blit(buffer,screen,0,0,0,10,WIDTH,HEIGHT);
}
}
Here's what happens...when I press enter at the main screen, it goes into the PlaceBet function, and updates the bet according to the keys pressed (so I know it's entering the while loop in PlaceBet). One thing is that it updates the keys TOO fast, so if I press + it goes up at least $50. But the big problem is that pressing ENTER doesn't end the while loop. When I press enter, it doesn't do anything at all actually. According to my code, it should exit the while loop and go back to main. Then, I should still be in the main while loop. So if I press ESC it should quit. But it doesn't do anything. I suspect I need to clear_keybuf() somewhere but I don't know where...any ideaS?