I have this example file that I've been using to get used to the perks of Allegro, but the file is written in an earlier version of Allegro than 4.2.2. There are only a few errors, but I don't know how to fix them! I'll post the code and the compiler output. If it makes any difference(i doubt it), I am using Dev-C++ 4.9.9.2.

#include <allegro.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <string>
int backcol;
int groundcol;
int snowcol;
int grav = 1;
int paintcol;
BITMAP *buffer;
std::string paintname = "Snow";
int mx, my, mx2, my2;
int close_b = 0;
int zahler = 1;
int SCREEN_WIDTH;
int SCREEN_HEIGHT;
void thick_line(BITMAP *bmp, int x, int y, int x_, int y_,int thickness, int color){
        int dx = x - x_;
        int dy = y - y_;
        int d = sqrtf(dx * dx + dy * dy);
        if (!d)
        return;

        int v[4 * 2];
        v[0] = x - thickness * dy / d;
        v[1] = y + thickness * dx / d;
        v[2] = x + thickness * dy / d;
        v[3] = y - thickness * dx / d;
        v[4] = x_ + thickness * dy / d;
        v[5] = y_ - thickness * dx / d;
        v[6] = x_ - thickness * dy / d;
        v[7] = y_ + thickness * dx / d;

        polygon(bmp, 4, v, color);
}

void close_button_handler(void)
{
      close_b = 1;
   zahler = 1;
}



int main()
{
     SCREEN_WIDTH = 620;
     SCREEN_HEIGHT = 240;
          allegro_init();
          install_keyboard();
          install_mouse();
          set_gfx_mode( GFX_AUTODETECT_WINDOWED, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
     show_mouse(screen);
          set_close_button_callback(close_button_handler);
         buffer = create_bitmap(SCREEN_WIDTH, SCREEN_HEIGHT);
BITMAP *outbuf = create_bitmap(SCREEN_WIDTH, SCREEN_HEIGHT);
          backcol = makecol( 0, 128, 255);
     groundcol = makecol( 0, 128, 50);
     snowcol = makecol( 255,255,255);
     paintcol = makecol(255,255,255);
          clear_to_color ( buffer, backcol);
          rectfill(buffer, 0, SCREEN_HEIGHT - 50, SCREEN_WIDTH, SCREEN_HEIGHT, groundcol);
     while(!key[KEY_ESC]){
          TickPhys(BITMAP *sand_buffer):void{
   int c, dir;
   for (int y = SCREEN_HEIGHT; y > -1; --y)
   {
      for(int x = SCREEN_WIDTH; x > -1; --x)
      {
         if(getpixel(sand_buffer, x, y) == snowcol)
         {
                dir = (rand()%3 - 1);
                if(getpixel(sand_buffer, x+dir, y+grav) == backcol){
                       putpixel(sand_buffer, x+dir, y+grav, snowcol);
                       putpixel(sand_buffer, x, y, backcol);
                }
                else
                {
                  if(getpixel(sand_buffer, x+dir, y+grav) != groundcol){
                    if(getpixel(sand_buffer, x+dir, y) == backcol){
                       putpixel(sand_buffer, x+dir, y, snowcol);
                      
                       putpixel(sand_buffer, x, y, backcol);
                
                    }
                  }
               }
         }
      }
     }
   return;
}


          void creategrains(BITMAP *buffer){
      mx2 = mx;
      my2 = my;
      mx = mouse_x;
      my = mouse_y;

      if(mouse_b){
      if(zahler == 1)
      {
      zahler =+ 1;
         thick_line(buffer, mx2, my2, mx, my, 5, paintcol);
         circlefill(buffer, mx, my, 5, paintcol);
            }
      }

}
          void checkselect(){
     if(key[KEY_1]){
     paintcol = snowcol;
     paintname = "Snow";
     }
     if(key[KEY_2]){
     paintcol = groundcol;
     paintname = "Ground";
     }
     if(key[KEY_3]){
     paintcol = backcol;          
     paintname = "Background";
     }
     if(key[KEY_R]){
     paintcol = snowcol;
     paintname = "Snow";
     clear_to_color ( buffer, backcol);
     rectfill(buffer, 0, SCREEN_HEIGHT - 50, SCREEN_WIDTH, SCREEN_HEIGHT, groundcol);
     }
}



          blit(buffer,outbuf,0,0,0,0,SCREEN_WIDTH,SCREEN_HEIGHT);
                      std::string msg = "Current Brush: " + paintname; 
           textout_ex(outbuf, font, msg.c_str(), 10, 10, snowcol, backcol);
           textout_ex(outbuf, font, "Press 'R' to Reset", 10, 20, snowcol, backcol);
                 clear_keybuf();   
     }  
     return 0;
}
END_OF_MAIN();

sorry if this doesn't autoformat (i don't know if it auomaitcally does).
Thanks fo any help... i don't really know what to do: change script, plugins, etc.

Recommended Answers

All 15 Replies

Where are the errors?

sorry about that:

In function'void thick_line(BITMAP*,int,int,int,int,int,int)':
32: warning:converting to 'int' from 'float'

In function 'int_mangled_main()':
90: error: expected primary-expression before '*' token
90: error: 'sand_buffer' undeclared (first use this function)
90: error: (Each undeclared identifier is reported only once for each function it appears in)
90: error: 'TickPhys' undeclared (first use this function)
90: error: expected ';' before ':' token
125: error: a function-definition is not allowed here before '{' token
125: error: expectd ',' or ';' before '{' token
142: error: expected primary-expression before "void"

Whew, that was a lot of typing(copy and paste didn't work) :(

Where is the function In function 'int_mangled_main() defined?

heres the lines for the errors:
32:

int d = sqrtf(dx * dx + dy * dy);

90:

TickPhys(BITMAP *sand_buffer):void{

125:

void creategrains(BITMAP *buffer){

142:

void checkselect(){

thanks for all the interest so far...

Note: when I try to change line 32 to a float, v also has to be changed to float which doen't work because v has to be a constant integer for polygon to work. :P

Line 32 is not a error , it is a warning, So its okay, However

I dont understand the need of :void in line 90. Try removing that.

Though on line 142 and 125, I think you will need to post down some more code surrounding it to know...

I deleted void on line 90, still give those 4 errors.
Here is the script around 125:(its in the while loop)

void creategrains(BITMAP *buffer){
      mx2 = mx;
      my2 = my;
      mx = mouse_x;
      my = mouse_y;

      if(mouse_b){
      if(zahler == 1)
      {
      zahler =+ 1;
         thick_line(buffer, mx2, my2, mx, my, 5, paintcol);
         circlefill(buffer, mx, my, 5, paintcol);
      //Using both of these functions makes a nice clean draw....      
      }
      }

}

and here is the code for 142: (also in the while loop)

void checkselect(){
     if(key[KEY_1]){
     paintcol = snowcol;
     paintname = "Snow";
     }
     if(key[KEY_2]){
     paintcol = groundcol;
     paintname = "Ground";
     }
     if(key[KEY_3]){
     paintcol = backcol;          
     paintname = "Background";
     }
     if(key[KEY_R]){
     paintcol = snowcol;
     paintname = "Snow";
     clear_to_color ( buffer, backcol);
     rectfill(buffer, 0, SCREEN_HEIGHT - 50, SCREEN_WIDTH, SCREEN_HEIGHT, groundcol);
     }
}

So all this code is inside a while loop??????

Hey It is an error to define a function inside another function .. The function definitions should be indepandant or global.

where is this? I'm having trouble seperating the function prototypes form the lines that call the function.

i mean

int main()
{

  while(expression)
      {
          func1 ()
             {
              do this in func1
             }
       }//While loop end
}//Main End.

This isnt valid right.

Here is the script around 125its in the while loop)

Makes it sound as if the above format is true,

Why Dont you post down the whole code in the [code=cplusplus] [/code] code tags.

#include <allegro.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <string>
//Theres a time and Place for everything. And these headers are good to have included...
//Allegro.h is ALLEGRO!!! Howd' you guess???

int backcol;
int groundcol;
int snowcol;
//The three above variables are the colors of three elements. Snow, Ground, and Background(Nothing)
int grav = 1;
//^^The Gravity Multiplier
int paintcol;
//^^The current color of the Brush
BITMAP *buffer;
//^^The buffer bitmap used for flipping on to the screen
std::string paintname = "Snow";
//^^The name of the currently selected Element(Used for the interface)
int mx, my, mx2, my2;
int close_b = 0;
int zahler = 1;
//Mouse Variables
int SCREEN_WIDTH;
int SCREEN_HEIGHT;
//Everything should be bundled up when possible, Including Screen Dimensions. It makes things MUCH easier in the future...
void thick_line(BITMAP *bmp, int x, int y, int x_, int y_,int thickness, int color){
        int dx = x - x_;
        int dy = y - y_;
        int d = sqrtf(dx * dx + dy * dy);
        if (!d)
        return;

        int v[4 * 2];
        v[0] = x - thickness * dy / d;
        v[1] = y + thickness * dx / d;
        v[2] = x + thickness * dy / d;
        v[3] = y - thickness * dx / d;
        v[4] = x_ + thickness * dy / d;
        v[5] = y_ - thickness * dx / d;
        v[6] = x_ - thickness * dy / d;
        v[7] = y_ + thickness * dx / d;

        polygon(bmp, 4, v, color);
//This draws a THICK line.
}
void close_button_handler(void){
   //This resets variables when the mouse button is released...
   close_b = 1;
   zahler = 1;
}
int main()
{
     SCREEN_WIDTH = 620;
     SCREEN_HEIGHT = 240;
     //Setting the Screen width and Height
     allegro_init();
     //Starting up Allegro
     install_keyboard();
     //Enabling the keyboard
     install_mouse();
     //Enabling the mouse
     set_gfx_mode( GFX_AUTODETECT_WINDOWED, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
     //Setting the graphics mode(I went with Windowed...)
     show_mouse(screen);
     //Shows the mouse on the screen...
     set_close_button_callback(close_button_handler);
     //Thats for later in the tuorial...
     buffer = create_bitmap(SCREEN_WIDTH, SCREEN_HEIGHT);
     //The enviornment buffer(for grains and elements to be painted on
     BITMAP *outbuf = create_bitmap(SCREEN_WIDTH, SCREEN_HEIGHT);
     //The second buffer(Used for the Overlays)
     backcol = makecol( 0, 128, 255);
     groundcol = makecol( 0, 128, 50);
     snowcol = makecol( 255,255,255);
     paintcol = makecol(255,255,255);
     //Setting the color of the elements(You can change them...)
     clear_to_color ( buffer, backcol);
     //Clearing the buffer to the background color
     rectfill(buffer, 0, SCREEN_HEIGHT - 50, SCREEN_WIDTH, SCREEN_HEIGHT, groundcol);
     //Creating Ground for the snow to fall on
     while(!key[KEY_ESC]){
          TickPhys(BITMAP *sand_buffer){
               int c, dir;
               for (int y = SCREEN_HEIGHT; y > -1; --y){
                    for(int x = SCREEN_WIDTH; x > -1; --x){
                         if(getpixel(sand_buffer, x, y) == snowcol){
                              dir = (rand()%3 - 1);
                              //^^This creates a random left,right, or center movement in the grain...
                              if(getpixel(sand_buffer, x+dir, y+grav) == backcol){
                                   putpixel(sand_buffer, x+dir, y+grav, snowcol);
                                   //Draw the new position of the grain
                                   putpixel(sand_buffer, x, y, backcol);
                                   //Clear the old one...
                              }else{
                                   //This 'If' Statement makes sure the grains won't shuffle around on the ground....
                                   if(getpixel(sand_buffer, x+dir, y+grav) != groundcol){
                                        if(getpixel(sand_buffer, x+dir, y) == backcol){
                                             putpixel(sand_buffer, x+dir, y, snowcol);
                                             //Draw the new position of the grain
                                             putpixel(sand_buffer, x, y, backcol);
                                             //Clear the old one....
                                        }
                                   }
                              }
                         }
                    }
               }
               return;
          }
          void creategrains(BITMAP *buffer){
               mx2 = mx;
               my2 = my;
               mx = mouse_x;
               my = mouse_y;
               if(mouse_b){
                    if(zahler == 1){
                         zahler =+ 1;
                         thick_line(buffer, mx2, my2, mx, my, 5, paintcol);
                         circlefill(buffer, mx, my, 5, paintcol);
                         //Using both of these functions makes a nice clean draw....      
                    }
               }
          }
          void checkselect(){
               if(key[KEY_1]){
                    paintcol = snowcol;
                    paintname = "Snow";
               }
               if(key[KEY_2]){
                    paintcol = groundcol;
                    paintname = "Ground";
               }
               if(key[KEY_3]){
                    paintcol = backcol;          
                    paintname = "Background";
               }
               if(key[KEY_R]){
                    paintcol = snowcol;
                    paintname = "Snow";
                    clear_to_color ( buffer, backcol);
                    rectfill(buffer, 0, SCREEN_HEIGHT - 50, SCREEN_WIDTH, SCREEN_HEIGHT, groundcol);
               }
          }
          blit(buffer,outbuf,0,0,0,0,SCREEN_WIDTH,SCREEN_HEIGHT);
          //Print the enviornment buffer to the overlay buffer
          std::string msg = "Current Brush: " + paintname; 
          textout_ex(outbuf, font, msg.c_str(), 10, 10, snowcol, backcol);
          textout_ex(outbuf, font, "Press 'R' to Reset", 10, 20, snowcol, backcol);
          //Print the OVerlays on the screen
          blit(outbuf,screen,0,0,0,0,SCREEN_WIDTH,SCREEN_HEIGHT);
          //Print the final buffer to the screen...
          /* Why do I do it this way??? Because you don't want to print text onto the environment buffer because it will turn into sand or act like an element. And you don't want to print it directly to the screen or you will get 
          flicker... So, I have the first buffer for the environment, the second buffer for the overlays, and then I print that to the screen. It works well. Nice and clean, no flicker*/
          clear_keybuf();
          //Loop until Escape is Pressed....     
     }  
     return 0;
}
END_OF_MAIN();
//You need that...

here it is will all the comments in it

Hey , ALL the function definitions should be outside the Main function.......

SO put them out of the while loop and call them..

heres what I put in front of the while, now there is only that warning about converting to int from float and this error: expected ',' or ';' before "TickPhys" (line 2)

BITMAP *sand_buffer=buffer
TickPhys(BITMAP *sand_buffer)
void creategrains(BITMAP *buffer)
void checkselect()

Try this

BITMAP *sand_buffer=buffer
TickPhys(sand_buffer)
creategrains(*sand_buffer)
checkselect()

here is the updated code:

#include <allegro.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <string>
//Theres a time and Place for everything. And these headers are good to have included...
//Allegro.h is ALLEGRO!!! Howd' you guess???

int backcol;
int groundcol;
int snowcol;
//The three above variables are the colors of three elements. Snow, Ground, and Background(Nothing)
int grav = 1;
//^^The Gravity Multiplier
int paintcol;
//^^The current color of the Brush
BITMAP *buffer;
//^^The buffer bitmap used for flipping on to the screen
std::string paintname = "Snow";
//^^The name of the currently selected Element(Used for the interface)
int mx, my, mx2, my2;
int close_b = 0;
int zahler = 1;
//Mouse Variables
int SCREEN_WIDTH;
int SCREEN_HEIGHT;
//Everything should be bundled up when possible, Including Screen Dimensions. It makes things MUCH easier in the future...
void thick_line(BITMAP *bmp, int x, int y, int x_, int y_,int thickness, int color){
     int dx = x - x_;
     int dy = y - y_;
     int d = sqrtf(dx * dx + dy * dy);
     if (!d)
     return;

     int v[4 * 2];
     v[0] = x - thickness * dy / d;
     v[1] = y + thickness * dx / d;
     v[2] = x + thickness * dy / d;
     v[3] = y - thickness * dx / d;
     v[4] = x_ + thickness * dy / d;
     v[5] = y_ - thickness * dx / d;
     v[6] = x_ - thickness * dy / d;
     v[7] = y_ + thickness * dx / d;

     polygon(bmp, 4, v, color);
     //This draws a THICK line.
}
void close_button_handler(void){
   //This resets variables when the mouse button is released...
   close_b = 1;
   zahler = 1;
}
int main(int argc, char *argv[]){
     SCREEN_WIDTH = 620;
     SCREEN_HEIGHT = 240;
     //Setting the Screen width and Height
     allegro_init();
     //Starting up Allegro
     install_keyboard();
     //Enabling the keyboard
     install_mouse();
     //Enabling the mouse
     set_gfx_mode( GFX_AUTODETECT_WINDOWED, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
     //Setting the graphics mode(I went with Windowed...)
     show_mouse(screen);
     //Shows the mouse on the screen...
     set_close_button_callback(close_button_handler);
     //Thats for later in the tuorial...
     buffer = create_bitmap(SCREEN_WIDTH, SCREEN_HEIGHT);
     //The enviornment buffer(for grains and elements to be painted on
     BITMAP *outbuf = create_bitmap(SCREEN_WIDTH, SCREEN_HEIGHT);
     //The second buffer(Used for the Overlays)
     backcol = makecol( 0, 128, 255);
     groundcol = makecol( 0, 128, 50);
     snowcol = makecol( 255,255,255);
     paintcol = makecol(255,255,255);
     //Setting the color of the elements(You can change them...)
     clear_to_color ( buffer, backcol);
     //Clearing the buffer to the background color
     rectfill(buffer, 0, SCREEN_HEIGHT - 50, SCREEN_WIDTH, SCREEN_HEIGHT, groundcol);
     //Creating Ground for the snow to fall on
     BITMAP *sand_buffer=buffer;
     TickPhys(sand_buffer);
     creategrains(*sand_buffer);
     checkselect();
     while(!key[KEY_ESC]){
          TickPhys(BITMAP *buffer){
               int c, dir;
               for (int y = SCREEN_HEIGHT; y > -1; --y){
                    for(int x = SCREEN_WIDTH; x > -1; --x){
                         if(getpixel(buffer, x, y) == snowcol){
                              dir = (rand()%3 - 1);
                              //^^This creates a random left,right, or center movement in the grain...
                              if(getpixel(buffer, x+dir, y+grav) == backcol){
                                   putpixel(buffer, x+dir, y+grav, snowcol);
                                   //Draw the new position of the grain
                                   putpixel(buffer, x, y, backcol);
                                   //Clear the old one...
                              }else{
                                   //This 'If' Statement makes sure the grains won't shuffle around on the ground....
                                   if(getpixel(buffer, x+dir, y+grav) != groundcol){
                                        if(getpixel(buffer, x+dir, y) == backcol){
                                             putpixel(buffer, x+dir, y, snowcol);
                                             //Draw the new position of the grain
                                             putpixel(buffer, x, y, backcol);
                                             //Clear the old one....
                                        }
                                   }
                              }
                         }
                    }
               }
               return;
          }
          void creategrains(BITMAP *buffer){
               mx2 = mx;
               my2 = my;
               mx = mouse_x;
               my = mouse_y;
               if(mouse_b){
                    if(zahler == 1){
                         zahler =+ 1;
                         thick_line(buffer, mx2, my2, mx, my, 5, paintcol);
                         circlefill(buffer, mx, my, 5, paintcol);
                         //Using both of these functions makes a nice clean draw....      
                    }
               }
          }
          void checkselect(){
               if(key[KEY_1]){
                    paintcol = snowcol;
                    paintname = "Snow";
               }
               if(key[KEY_2]){
                    paintcol = groundcol;
                    paintname = "Ground";
               }
               if(key[KEY_3]){
                    paintcol = backcol;          
                    paintname = "Background";
               }
               if(key[KEY_R]){
                    paintcol = snowcol;
                    paintname = "Snow";
                    clear_to_color ( buffer, backcol);
                    rectfill(buffer, 0, SCREEN_HEIGHT - 50, SCREEN_WIDTH, SCREEN_HEIGHT, groundcol);
               }
          }
          blit(buffer,outbuf,0,0,0,0,SCREEN_WIDTH,SCREEN_HEIGHT);
          //Print the enviornment buffer to the overlay buffer
          std::string msg = "Current Brush: " + paintname; 
          textout_ex(outbuf, font, msg.c_str(), 10, 10, snowcol, backcol);
          textout_ex(outbuf, font, "Press 'R' to Reset", 10, 20, snowcol, backcol);
          //Print the OVerlays on the screen
          blit(outbuf,screen,0,0,0,0,SCREEN_WIDTH,SCREEN_HEIGHT);
          //Print the final buffer to the screen...
          /* Why do I do it this way??? Because you don't want to print text onto the environment buffer because it will turn into sand or act like an element. And you don't want to print it directly to the screen or you will get 
          flicker... So, I have the first buffer for the environment, the second buffer for the overlays, and then I print that to the screen. It works well. Nice and clean, no flicker*/
          clear_keybuf();
          //Loop until Escape is Pressed....     
     }  
     return 0;
}
END_OF_MAIN();
//You need that...

and the errors...

In function `int _mangled_main(int, char**)':
84: error: `TickPhys' undeclared (first use this function)
85: error: `creategrains' undeclared (first use this function)
86: error: `checkselect' undeclared (first use this function)
90: error: expected primary-expression before '*' token
90: error: expected `;' before '{' token
118: error: a function-definition is not allowed here before '{' token
118: error: expected `,' or `;' before '{' token
132: error: expected primary-expression before "void"
132: error: expected `;' before "void"

Help!!!! :S

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.