|
Loop doesn't work. |
SaSSolino
Member #16,806
February 2018
|
Hi guys, I'm trying to create a simple tic tac toe game. The inputs are supposed to come from the keyboard, but I'm having issues making it work as I always seem to land on event.type = ALLEGRO_EVENT_TIMER. What am I doing wrong? Here's my events related code: ALLEGRO_TIMER *timer = NULL; al_install_keyboard(); timer = al_create_timer(0.04); event_q = al_create_event_queue(); al_register_event_source(event_q, al_get_keyboard_event_source()); al_start_timer(timer); loop ALLEGRO_EVENT event; al_wait_for_event(event_q, &event); if (event.type = ALLEGRO_EVENT_TIMER) { if (redraw == true && al_is_event_queue_empty(event_q)) { loop ends al_destroy_timer(timer); |
Edgar Reynaldo
Major Reynaldo
May 2007
|
SaSSolino said:
if (event.type = ALLEGRO_EVENT_TIMER) { redraw = true; } else if (event.type = ALLEGRO_EVENT_KEY_DOWN) {
See anything wrong with that code? You're performing assignment, and then the result gets cast to bool, which is probably always true. That's why your event.type is never ALLEGRO_EVENT_KEY_DOWN. You need to test for equivalence with the == operator. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
SaSSolino
Member #16,806
February 2018
|
Oh god, I'm quite embarrassed about this one. Thanks! |
Edgar Reynaldo
Major Reynaldo
May 2007
|
You can make the compiler work for you. Reverse the order of the arguments. if (ALLEGRO_EVENT_TIMER = ev.type) {/// error if const, warning about truth expression }
My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
SaSSolino
Member #16,806
February 2018
|
Solved this, but now I have another issue that I recreated the events to solve but apparently it's bugged still. Basically when I touch a key, it triggers multiple times, as if I was pressing up to move forward for example. I just want single key presses though, how do I do that? EDIT: nvm got it |
|