In this part of code is an error. It says
"Run-Time Check Failure #3 - The variable 'direct' is being used without being initialized."
How can I fix this error ?
bool loop=true;
int direct;
al_install_keyboard();
ALLEGRO_TIMER *timer = al_create_timer (0.4);
ALLEGRO_EVENT_QUEUE *keystroke = al_create_event_queue();
al_register_event_source(keystroke ,al_get_keyboard_event_source() );
al_register_event_source (keystroke , al_get_timer_event_source(timer));
al_start_timer(timer);
do{
ALLEGRO_EVENT input;
al_wait_for_event(keystroke , &input );
if (input.type == ALLEGRO_EVENT_KEY_DOWN){
switch(input.keyboard.keycode){
case ALLEGRO_KEY_DOWN: direct=DOWN; break;
case ALLEGRO_KEY_UP : direct=UP;break;
case ALLEGRO_KEY_LEFT: direct=LEFT;break;
case ALLEGRO_KEY_RIGHT: direct=RIGHT;break;
case ALLEGRO_KEY_ESCAPE: loop= false;
}
}
if(input.type==ALLEGRO_EVENT_TIMER){
switch(direct){
case DOWN: moove_snake(DOWN) ; break;
case UP: moove_snake(UP) ; break;
case LEFT: moove_snake(LEFT) ; break;
case RIGHT: moove_snake(RIGHT) ; break;
}
}
}while (loop);
initialize it :)
int direct = 0;