Advertisement

Initializer element is not constant...

Started by June 09, 2000 10:29 AM
1 comment, last by Tsutomegi 24 years, 6 months ago
When i compile my little program, i get the error "initializer element is not constant..." here''s some of the code: #include #include #include "nvdata.h" DATAFILE *nv; BITMAP *layerfive = create_bitmap(800,600); //background images (bottom) BITMAP *layerfour = create_bitmap(800,600); //sprites BITMAP *layerthree = create_bitmap(800,600); //backgrond images (top layer) BITMAP *layertwo = create_bitmap(800,600); //messages BITMAP *layerone = create_bitmap(800,600); //text loadbg(int whichone){ clear(layerfive); if(whichone==0){blit(nv[engine].dat,layerfive,0,0,0,0,800,600);} (there''s more here, i just cut it out...) blit(layerfive,screen,0,0,0,0,800,600);} it says the problem is with the BITMAP *... lines. this is just one file that i have linked to all the others... in main.c i have set the graphics mode, and the color depth, and everything else...
Oh yeah... i use allegro and djgpp...
might be important...
Advertisement
Since the create_bitmap() function isn't a constant function, you can't use it as an initializer.

Do this instead:

DATAFILE *nv;

BITMAP *layerfive = NULL;
BITMAP *layerfour = NULL;
BITMAP *layerthree = NULL;
BITMAP *layertwo = NULL;
BITMAP *layerone = NULL;

void InitBmps(void)
{
layerfive = create_bitmap(800,600); //background images (bottom)
layerfour = create_bitmap(800,600); //sprites
layerthree = create_bitmap(800,600); //backgrond images (top layer)
layertwo = create_bitmap(800,600); //messages
layerone = create_bitmap(800,600); //text

// Always clear bitmaps after they have been created!
clear(layerfive);
clear(layerfour);
clear(layerthree);
clear(layertwo);
clear(layerone);
}

Then simply call the InitBmps function when you want the bmps to be created (in your main() for example).

I recommend that you do some error checking inside the InitBmps function to see if you're out of memory (check if any of the bitmap pointers are NULL, and if anyone of them is NULL then exit the program), but I think you can do that by yourself

/. Muzzafarath
Mad House Software

Edited by - Muzzafarath on June 9, 2000 12:18:24 PM
I'm reminded of the day my daughter came in, looked over my shoulder at some Perl 4 code, and said, "What is that, swearing?" - Larry Wall

This topic is closed to new replies.

Advertisement