Hey guys, I'm new to Allegro and have been following some tutorials. I'm not new to game programming so I understand the concept of ALLEGRO_EVENT_KEY_DOWN and that it registers the initial keypress and not the hold. When I run my program, it registers the key being held down as continuous ALLEGRO_EVENT_KEY_DOWN events. I'm not using custom KB software that would turn trigger key presses when I hold the key down, so I am not sure what is going on. The guy in the video specifically says his doesn't repeat when the key is held down. Any ideas? Here is the code:
You need to enable warnings. You have an assignment on line 44 when you're trying to test for equality.
if(ev.type = ALLEGRO_EVENT_KEY_DOWN)
should be
if(ev.type == ALLEGRO_EVENT_KEY_DOWN)
Wow, I can't believe I missed that one. Sheesh! Thanks for the catch!
I didn't see it myself either, the compiler told me when I habitually use the -Wall switch. (Warn all errors)
t.c:44:3: warning: suggest parentheses around assignment used as truth value [-Wparentheses] if(ev.type = ALLEGRO_EVENT_KEY_DOWN)
Confusingly -Wall doesn't actually enable all warnings. You need -Wextra as well I think.
Indeed. (In the past -Wextra was called just -W.) I always use this:
gcc -Wall -Wextra -Werror
I tend to only use -Werror in special cases. I hate getting stuck in unimportant warnings.
Actually for this program gcc was complaining about al_show_native_message_box() too, it doesn't like NULL for the flags.