Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎲 GameMaker

Function problems

Started by Drezard Jan 21, 2007 at 8:02 PM 2 replies 550+ views
Original Post
Drezard
Drezard
Hello, Im trying to make an allegro game. Here is my code: Code: #include // include the basic header for allegro #include // include the basic header for c++ functions #include // include the basic header for file i/o #include // include the basic header for using strings using namespace std; // c++ specify int main() { // main function int res; // used for error handling struct scenery { // declare a struct to hold all the scenery BITMAP *spr_background; // declare a bitmap for a background BITMAP *spr_box; // declare a bitmap for a box } struct player { // declare a struct to hold all the players information BITMAP *spr_player; // declare a bitmap for a player int x, y; // players x and y coords } allegro_init(); // initialize allegro set_color_depth(32); // set the color depth res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 1280, 1024, 0, 0); // set the screen resolution if (res != 0) { // error check if setting the screen resolution failed allegro_message(allegro_error); // give the player a message exit(-1); // exit the program } install_timer(); // intialize timers in allegro install_keyboard(); // intialize keyboard routines in allegro install_mouse(); // intialize mouse routines in allegro player.spr_player = load_bitmap( "player.bmp", NULL); // load the bitmap for the player player.spr_background = load_bitmap( "background.bmp", NULL); // load the bitmap for the background player.spr_box = load_bitmap( "box.bmp", NULL); // load the bitmap for the box player.x = 300; // set some default player coordinates player.y = 300; // while (false) { // start the GAME LOOP } // end the GAME LOOP return 0; // end the program } END_OF_MAIN() // allegro specify (well commented eh?) Now I get an error when i try and compile this code: Quote: Error: Line 26 - two or more data types in declaration of 'install_allegro' Line 26 - no matching function for call to '_mangled_main()::scenery::scenery(int, int*, int(*)void(*)))" Now whats wrong with my code? Are there n e more errors u can find? - Cheers, Daniel
TheUnbeliever
TheUnbeliever
I'll take a look, but I'm formatting it for our sanity:

#include <allegro.h> // include the basic header for allegro#include <iostream> // include the basic header for c++ functions#include <fstream> // include the basic header for file i/o#include <string> // include the basic header for using stringsusing namespace std; // c++ specify int main() { // main function    int res; // used for error handling    struct scenery { // declare a struct to hold all the scenery        BITMAP *spr_background; // declare a bitmap for a background        BITMAP *spr_box; // declare a bitmap for a box    }    struct player { // declare a struct to hold all the players information        BITMAP *spr_player; // declare a bitmap for a player        int x, y; // players x and y coords    }    allegro_init(); // initialize allegro    set_color_depth(32); // set the color depth    res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 1280, 1024, 0, 0); // set the screen resolution    if (res != 0) { // error check if setting the screen resolution failed        allegro_message(allegro_error); // give the player a message        exit(-1); // exit the program    }    install_timer(); // intialize timers in allegro    install_keyboard(); // intialize keyboard routines in allegro    install_mouse(); // intialize mouse routines in allegro    player.spr_player = load_bitmap( "player.bmp", NULL); // load the bitmap for the player    player.spr_background = load_bitmap( "background.bmp", NULL); // load the bitmap for the background    player.spr_box = load_bitmap( "box.bmp", NULL); // load the bitmap for the box     player.x = 300; // set some default player coordinates    player.y = 300; //    while (false) { // start the GAME LOOP    } // end the GAME LOOP    return 0; // end the program}END_OF_MAIN() // allegro specify


EDIT: Nope, I haven't a clue - but the formatting may increase your chances of a response. Enclose it in [source]//Your code here[/source] next time. :-)
[TheUnbeliever]
nobodynews
nobodynews
Two things:

semicolons after you struct definitions

eg struct alpha { int beta; }; // semicolon!

Also, while it's legal(I think) to put a struct definition in a function, I don't think that's right in this situation. Put them before main unless you have a reason to put them in a function.

Hope that helps.

Edit: I lied, there's a third thing. You provide a definition of a struct point, but never make an object of that type. You treat the definition AS the object.

#include <allegro.h> // include the basic header for allegro#include <iostream> // include the basic header for c++ functions#include <fstream> // include the basic header for file i/o#include <string> // include the basic header for using stringsusing namespace std; // c++ specify struct scenery { // declare a struct to hold all the scenery        BITMAP *spr_background; // declare a bitmap for a background        BITMAP *spr_box; // declare a bitmap for a box};struct player { // declare a struct to hold all the players information        BITMAP *spr_player; // declare a bitmap for a player        int x, y; // players x and y coords};int main() { // main function    int res; // used for error handling    allegro_init(); // initialize allegro    set_color_depth(32); // set the color depth    res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 1280, 1024, 0, 0); // set the screen resolution    if (res != 0) { // error check if setting the screen resolution failed        allegro_message(allegro_error); // give the player a message        exit(-1); // exit the program    }    install_timer(); // intialize timers in allegro    install_keyboard(); // intialize keyboard routines in allegro    install_mouse(); // intialize mouse routines in allegro    player user; // create an object called user of type player    user.spr_player = load_bitmap( "player.bmp", NULL); // load the bitmap for the player    user.spr_background = load_bitmap( "background.bmp", NULL); // load the bitmap for the background    user.spr_box = load_bitmap( "box.bmp", NULL); // load the bitmap for the box     user.x = 300; // set some default player coordinates    user.y = 300; //    while (false) { // start the GAME LOOP    } // end the GAME LOOP    return 0; // end the program}END_OF_MAIN() // allegro specify
C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) ,
Drezard
Drezard
cheers for the source thing. (I tried the bb code way but that didnt work).

Ill try those 3 things now.

Cheers, Daniel

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.