Posted on 12-29-2005 4:43 PM
hey, umm
int do_menu(MENU *menu, int x, int y);
i can't get it to work..i tried
MENU* aMenu;
//then
do_menu(aMenu, 200, 200);
//but the program crashed..so then i looked into MENU
//its a struct,
//typedef struct MENU
// char *text; - the text to display for the menu item
int (*proc)(void); - called when the menu item is clicked
struct MENU *child; - nested child menu
int flags; - disabled or checked state
void *dp; - pointer to any data you need
//sodo i need to define aMenu or what? i need help
ohhh, ok , thanks ...that made me understand the allegro api like a lot better
The crash was because the pointer was null (eg. not set). You need an array of MENU objects instead of an empty pointer (as in BAF's code)
You're welcome. Welcome to Allegro.cc, by the way... I forgot to say that in my post in your other thread.
btw, im using c++ not c
can u give it to me in c form?
because this is what i had
1 | #include <allegro.h> |
2 | |
3 | int main(void) |
4 | { |
5 | allegro_init(); |
6 | install_keyboard(); |
7 | |
8 | MENU mymenu[] |
9 | { |
10 | "Menu item name", myfunc, NULL /* can be a child menu item */, 0, NULL }, NULL, NULL, NULL, 0, NULL} |
11 | }; |
12 | |
13 | |
14 | |
15 | acquire_screen(); |
16 | |
17 | do_menu(mymenu, 200, 200); |
18 | |
19 | release_screen(); |
20 | |
21 | readkey; |
22 | |
23 | return 0; |
24 | } |
25 | |
26 | END_OF_MAIN(); |
/errors
Project : Win32 Application
Compiler : GNU GCC Compiler (called directly)
Directory : C:\Documents and Settings\Lavontae\Desktop\
--------------------------------------------------------------------------------
Switching to target: default
Compiling: main.cpp
main.cpp: In function `int _mangled_main()':
main.cpp:8: error: expected primary-expression before "mymenu"
main.cpp:8: error: expected `;' before "mymenu"
main.cpp:10: error: expected primary-expression before ',' token
main.cpp:10: error: expected `;' before '}' token
main.cpp: At global scope:
main.cpp:11: error: expected declaration before '}' token
Process terminated with status 1 (0 minutes, 2 seconds)
you missed the = sign off the array definition.
also, when you use some of the GUI stuff, you have to make explicit casts when using C++.
btw, if you are looking at gui stuff, you could always look in the library section at 'masking', it's a c++ based GUI that produces something a lot prettier.
ummm..
1 | #include <allegro.h> |
2 | |
3 | int main(void) |
4 | { |
5 | allegro_init(); |
6 | install_keyboard(); |
7 | MENU mymenu[]; |
8 | |
9 | |
10 | |
11 | |
12 | acquire_screen(); |
13 | |
14 | do_menu(mymenu, 200, 200); |
15 | |
16 | release_screen(); |
17 | |
18 | readkey; |
19 | |
20 | return 0; |
21 | } |
22 | |
23 | END_OF_MAIN(); |
24 | |
25 | MENU mymenu[] = { |
26 | { "Menu item name", main, NULL /* can be a child menu item */, 0, NULL }, |
27 | { NULL, NULL, NULL, 0, NULL} |
28 | }; |
/errors
Project : Win32 Application
Compiler : GNU GCC Compiler (called directly)
Directory : C:\Documents and Settings\Lavontae\Desktop\
--------------------------------------------------------------------------------
Switching to target: default
Compiling: main.cpp
main.cpp: In function `int _mangled_main()':
main.cpp:7: error: storage size of `mymenu' isn't known
main.cpp:18: warning: statement is a reference, not call, to function `readkey'
Process terminated with status 1 (0 minutes, 1 seconds)
Why are you trying to call main from your menu? And you cant define your menu as nothing in main then expect it to work. And readkey should be readkey().
what do u mean define my menu as nothing?
is this right?
1 | #include <allegro.h> |
2 | |
3 | int main(void) |
4 | { |
5 | allegro_init(); |
6 | install_keyboard(); |
7 | |
8 | |
9 | |
10 | |
11 | acquire_screen(); |
12 | |
13 | do_menu(mymenu, 200, 200); |
14 | |
15 | release_screen(); |
16 | |
17 | readkey(); |
18 | |
19 | return 0; |
20 | } |
21 | |
22 | END_OF_MAIN(); |
23 | |
24 | MENU mymenu[] = { |
25 | { "Menu item name", myFunc, NULL /* can be a child menu item */, 0, NULL }, |
26 | { NULL, NULL, NULL, 0, NULL} |
27 | }; |
28 | |
29 | void myFunc() |
30 | { |
31 | } |
make yourself clearer please
http://www.allegro.cc/resource/resource-view.php?id=63
Is Miran's MasKinG (put random letters capitalised) and will probably suite you better as it is c++, easy to use, and has lots of simple examples.
If you haven't seen it yet, Allegro comes with a couple of example programmes that you can learn from (in allegro/examples/). For instance exgui.c (attached; I didn't know posts had a size limit...)
It's not the shortest possible programme that shows you how to do menus or use the GUI (which, by the way, is not great for use inside an actual game because it's quite ugly unless you use your own dialog routines), but it is intended to show you how things work and explain things.
One more suggestion, if I may:
u
Please take the extra two keystrokes and write it out as `you'. For me, `u' is a sound that doesn't even exist in English and seeing it where `you' is intended interrupts the flow of the text. In other words, it makes it harder for me to read and I find it annoying.
thanks neil, thats great...i don't possibly see how these people code games in C, i have to have classes
C to me is unorganized like h**l
Try this site: http://www.cprogramming.com/tutorial.html
It's where I learned most of the basics. I remember how nonsensical it all seemed, and I thought I'd never get past the boring stuff.. but because I couldn't give up the chance to make cool games, I kept at it. I suggest you do the same.
By the way, if you're wondering whether to do the C tutorials or C++ tutorials, it might not matter. I started on C++ and I still understand+write plain C code. Starting in plain C might introduce another learning curve if you start C++ later on, though.
umm, sorry to burst your bubble ION, but i know c++, when i said classes i mean OO classes,
when i said classes i mean OO classes
Oh, whoops
sorry to burst your bubble ION, but i know c++
You may know C++, but do you how to use it to create games from scratch? IE, create a main loop and set different functions for input, drawing, and logic?
Is Miran's MasKinG (put random letters capitalised) and will probably suite you better as it is c++, easy to use, and has lots of simple examples.
Its MASkinG. Easy to remember. M and A are his initials, Skin for skinnable, and G for GUI.
umm, sorry to burst your bubble ION, but i know c++
Don't be so quick to attack people, remember they are trying to help you (for free at that!). A few points that I don't think have been mentioned to you:
When you have a question do the following:
Make sure it is a question.
If it is about allegro, check the docs
If it's not in the docs, check the examples
If it's not there (almost everything is there FYI)
alright, im sorry. here is my source, i redid it. everytime i run it , it crashes.
what am i doing wrong?
1 | #include <allegro.h> |
2 | |
3 | |
4 | MENU mymenu[] = { |
5 | { "Menu item name", NULL, NULL /* can be a child menu item */, 0, NULL }, |
6 | { NULL, NULL, NULL, 0, NULL} |
7 | }; |
8 | |
9 | |
10 | |
11 | |
12 | int main(void) |
13 | { |
14 | allegro_init(); |
15 | install_keyboard(); |
16 | |
17 | |
18 | |
19 | |
20 | acquire_screen(); |
21 | |
22 | do_menu(mymenu, 200, 200); |
23 | |
24 | release_screen(); |
25 | |
26 | readkey(); |
27 | |
28 | return 0; |
29 | } |
30 | |
31 | END_OF_MAIN(); |
Don't you need to: set_gfx_mode
ok, i got it to work.
it was just some technical difficulties with the compiler , thanks
The color depth of the graphic mode has to be specified before calling this function with set_color_depth().
Also, you can use allegro_message() or, for a more acurate method, a debugger to find out where the program is crashing and then you can say more than "it crashes".
When I'm at work, I sometimes get a call from somebody saying "their computer doesn't work." That's a very vague statement and usually, it's something stupid. My first question is always, "is your monitor turned on?" (yes, sometimes that is the problem). So, with more details, it's easier to solve your problem.
Also, you can use allegro_message() [...] to find out where the program is crashing and then you can say more than "it crashes".
Note that you should not use allegro_message() after you've called set_gfx_mode(), unless you call set_gfx_mode(GFX_TEXT,...) again first.
The color depth of the graphic mode has to be specified before calling this function with set_color_depth().
You don't have to set the color depth (defaults to 8), but if you are going to set it, you must set it before setting the gfx mode.
ok, i got it to work.
it was just some technical difficulties with the compiler , thanks
Nah, the only problem was not calling set_gfx_mode.