is use Dev-c++ with allegro, und it gives me the error
expected primary-expression before "static"
when i try to comile the programm.
//fps-counter int maxSkip = 4; volatile int timerCounter = 0; static void timerCounterUpdater() { timerCounter++; } END_OF_STATIC_FUNCTION(timerCounterUpdater); LOCK_FUNCTION(timerCounterUpdater); LOCK_VARIABLE(timerCounter);
can you help me? i don't now what the programm means by this error, is it a syntax error???
Can you remove all the code and leave only the minimum necessary for the error to be triggered, then post it here? Maybe you forgot to put a } or ; somewhere above. Which is the exact line triggering the error?
that's the line where the compiler finds the error:
static void timerCounterUpdater()
it's an example from an learning-book, i can post the complete code (it isn't extremly much) if you want...
edit: that is the whole "function" or how i should call it:
static void timerCounterUpdater() { timerCounter++; }
Post it all, from what I see, the function is not the problem.
You must post the complete code.
1 | #include <allegro.h> |
2 | |
3 | int set_graphic_mode() { |
4 | set_color_depth(32); |
5 | if (set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 640, 480, 0, 0) >= 0) { |
6 | return 1; |
7 | } |
8 | set_color_depth(15); |
9 | if (set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 640, 480, 0, 0) >= 0) { |
10 | return 1; |
11 | } |
12 | set_color_depth(16); |
13 | if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0) >= 0) { |
14 | return 1; |
15 | } |
16 | return 0; |
17 | } |
18 | |
19 | int main(int argc, char **argv) { |
20 | allegro_init(); |
21 | install_keyboard(); |
22 | |
23 | if (!set_graphic_mode()) { |
24 | allegro_message("Unable to set graphic mode!"); |
25 | exit(0); |
26 | } |
27 | |
28 | //fps-counter |
29 | int maxSkip = 4; |
30 | volatile int timerCounter = 0; |
31 | static void timerCounterUpdater() |
32 | { |
33 | timerCounter++; |
34 | } END_OF_STATIC_FUNCTION(timerCounterUpdater); |
35 | |
36 | LOCK_FUNCTION(timerCounterUpdater); |
37 | LOCK_VARIABLE(timerCounter); |
38 | |
39 | // 60 aufrufe pro sec. |
40 | |
41 | install_int_ex(timerCounterUpdater, BPS_TO_TIMER(60)); |
42 | |
43 | curSkip = 0; |
44 | if (timerCounter > 0) { |
45 | do { |
46 | |
47 | //grafikmodus + fps gesetzt, beginnt mit eigebtlichen programmablauf |
48 | |
49 | install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, 0); |
50 | SAMPLE *test = load_sample("test.wav"); |
51 | play_sample (aoe, 255, 129, 1000, 1); |
52 | |
53 | BITMAP *doublebuffer = create_bitmap(SCREEN_W, SCREEN_H); |
54 | BITMAP *logo = load_bitmap("lord.tga", NULL); |
55 | |
56 | int x = 0; |
57 | int y = 0; |
58 | int dx = 1; |
59 | int dy = 1; |
60 | while (!keypressed()) { |
61 | |
62 | //---------------------------------------------- |
63 | // kollissionasbfrage anfang |
64 | // Linker und rechter Rand |
65 | if (x + dx < 0) { |
66 | dx *= -1; |
67 | } else if (x + logo->w >= SCREEN_W) { |
68 | dx *= -1; |
69 | } |
70 | // Oberer und unterer Rand |
71 | if (y + dy < 0) { |
72 | dy *= -1; |
73 | } else if (y + logo->h >= SCREEN_H) { |
74 | dy *= -1; |
75 | } |
76 | x+= dx; |
77 | y+= dy; |
78 | |
79 | //kollisionnsabfrage ende |
80 | //--------------------------------------------- |
81 | |
82 | //fps-controlls |
83 | cur.logic++; |
84 | timerCounter--; |
85 | curSkip++; |
86 | if (curSkip >= maxSkip |
87 | { |
88 | timerCounter = 0; |
89 | break; |
90 | } |
91 | |
92 | |
93 | } while (timerCounter > 0); |
94 | needsRefresh = TRUE; |
95 | } |
96 | |
97 | if (needsRefresh) |
98 | { |
99 | acquire_bitmap(doublebuffer); |
100 | clear(doublebuffer); // zeichnet bild |
101 | blit( logo, doublebuffer, 0, 0, x, y, logo->w, logo->h); //in den doublebuffer |
102 | release_bitmap(doublebuffer); |
103 | |
104 | blit(doublebuffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); |
105 | needsRefresh = FALSE; |
106 | |
107 | |
108 | } END_OF_MAIN(); |
yees, it's maybe not the cleanest code but it should work... the example in the book isn't very good explained. as you maybe see, it should be a fps-limiter-thing... i would like to use 60fps, if anyone knows a better solution for that problem
the other thing like sound, graphics etc works fine without the fps-part.
PS: don't care about the german comments
You can't declare a function inside another. Move the declaration of timerCounter and timerCounterUpdater outside main() (but keep the LOCK_* macros where they are).
If ReyBrujo posts this at the same time I do, I apologize for repeating
Move
int maxSkip = 4; volatile int timerCounter = 0; static void timerCounterUpdater() { timerCounter++; } END_OF_STATIC_FUNCTION(timerCounterUpdater);
above the main function (those lines should not be inside the main function, but outside it).
(Edit: Apologies for repeating! )
thank you! that fixed the problem
now it looks so:
1 | #include <allegro.h> |
2 | |
3 | int set_graphic_mode() { |
4 | set_color_depth(32); |
5 | if (set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 640, 480, 0, 0) >= 0) { |
6 | return 1; |
7 | } |
8 | set_color_depth(15); |
9 | if (set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 640, 480, 0, 0) >= 0) { |
10 | return 1; |
11 | } |
12 | set_color_depth(16); |
13 | if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0) >= 0) { |
14 | return 1; |
15 | } |
16 | return 0; |
17 | } |
18 | |
19 | //fps-counter |
20 | int maxSkip = 4; |
21 | volatile int timerCounter = 0; |
22 | static void timerCounterUpdater() |
23 | { |
24 | timerCounter++; |
25 | } END_OF_STATIC_FUNCTION(timerCounterUpdater); |
26 | |
27 | int main(int argc, char **argv) { |
28 | allegro_init(); |
29 | install_keyboard(); |
30 | |
31 | if (!set_graphic_mode()) { |
32 | allegro_message("Unable to set graphic mode!"); |
33 | exit(0); |
34 | } |
35 | |
36 | |
37 | |
38 | LOCK_FUNCTION(timerCounterUpdater); |
39 | LOCK_VARIABLE(timerCounter); |
40 | |
41 | // 60 aufrufe pro sec. |
42 | |
43 | install_int_ex(timerCounterUpdater, BPS_TO_TIMER(60)); |
44 | |
45 | int curSkip = 0; |
46 | if (timerCounter > 0) { |
47 | do { |
48 | |
49 | //grafikmodus + fps gesetzt, beginnt mit eigebtlichen programmablauf |
50 | |
51 | install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, 0); |
52 | SAMPLE *aoe = load_sample("aoe.wav"); |
53 | play_sample (aoe, 255, 129, 1000, 1); |
54 | |
55 | BITMAP *doublebuffer = create_bitmap(SCREEN_W, SCREEN_H); |
56 | BITMAP *logo = load_bitmap("lord.tga", NULL); |
57 | |
58 | int x = 0; |
59 | int y = 0; |
60 | int dx = 1; |
61 | int dy = 1; |
62 | while (!keypressed()) { |
63 | |
64 | //---------------------------------------------- |
65 | // kollissionasbfrage anfang |
66 | // Linker und rechter Rand |
67 | if (x + dx < 0) { |
68 | dx *= -1; |
69 | } else if (x + logo->w >= SCREEN_W) { |
70 | dx *= -1; |
71 | } |
72 | // Oberer und unterer Rand |
73 | if (y + dy < 0) { |
74 | dy *= -1; |
75 | } else if (y + logo->h >= SCREEN_H) { |
76 | dy *= -1; |
77 | } |
78 | x+= dx; |
79 | y+= dy; |
80 | |
81 | //kollisionnsabfrage ende |
82 | //--------------------------------------------- |
83 | |
84 | //fps-controlls |
85 | timerCounter--; |
86 | curSkip++; |
87 | if (curSkip >= maxSkip) |
88 | { |
89 | timerCounter = 0; |
90 | break; |
91 | } |
92 | |
93 | |
94 | } while (timerCounter > 0); |
95 | needsRefresh = TRUE; |
96 | |
97 | } |
98 | if (needsRefresh) |
99 | { |
100 | acquire_bitmap(doublebuffer); |
101 | clear(doublebuffer); // zeichnet bild |
102 | blit( logo, doublebuffer, 0, 0, x, y, logo->w, logo->h); //in den doublebuffer |
103 | release_bitmap(doublebuffer); |
104 | |
105 | blit(doublebuffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); |
106 | needsRefresh = FALSE; |
107 | |
108 | |
109 | } END_OF_MAIN(); |
but now theres an error on this line:
needsRefresh = FALSE; at the bottom of the whole code
error:
`needsRefresh' undeclared (first use this function)
whats wrong now? the same thing like above? wehn yes, i don't now where i should move this part
You don't have it defined anywhere. In the main function, where you define the variables, add int needsRefresh = FALSE;, that should fix it.