Advertisement

problem loading .dat data

Started by August 27, 2004 09:20 AM
18 comments, last by 23yrold3yrold 20 years, 3 months ago
ok in allegro im trying to use this function void drawAll() { blit( ( BITMAP* )data[ building ].dat, buffer, 0, 0, 0, 0, SCREEN_W, SCREEN_H ); acquire_screen(); blit( buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H ); release_screen(); } if my understanding of this function is right the filename[ spacific file ].datatype but my compiler says that data is undefined do i need to inclose this statement in () if i put it in "" i get a critical error error: `data' undeclared (first use this function)
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
Quote: Original post by raptorstrike
ok in allegro im trying to use this function
void drawAll()
{
blit( ( BITMAP* )data[ building ].dat, buffer,
0, 0, 0, 0, SCREEN_W, SCREEN_H );
acquire_screen();
blit( buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H );
release_screen();
}


if my understanding of this function is right the
filename[ spacific file ].datatype
but my compiler says that data is undefined do i need to inclose this statement in () if i put it in "" i get a critical error

error: `data' undeclared (first use this function)

Well, for one, isn't it not safe to do "data[ building ].dat"?? *the spaces are what I'm refering to*.
Advertisement
yeah i guesss your right but thats not the problem
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
Why would that be unsafe? It's just whitespace, the compiler will trim.
Where are you declaring data?
-ChadC
Well, here's the source for the datafile example...

/* *    Example program for the Allegro library, by Shawn Hargreaves. * *    This program demonstrates how to access the contents of an *    Allegro datafile (created by the grabber utility). */#include "allegro.h"/* the grabber produces this header, which contains defines for the names * of all the objects in the datafile (BIG_FONT, SILLY_BITMAP, etc). */#include "example.h"int main(int argc, char *argv[]){   DATAFILE *datafile;   char buf[256];   allegro_init();   install_keyboard();    if (set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0) {      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);      allegro_message("Unable to set any graphic mode\n%s\n", allegro_error);      return 1;   }   /* we still don't have a palette => Don't let Allegro twist colors */   set_color_conversion(COLORCONV_NONE);   /* load the datafile into memory */   replace_filename(buf, argv[0], "example.dat", sizeof(buf));   datafile = load_datafile(buf);   if (!datafile) {      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);      allegro_message("Error loading %s!\n", buf);      return 1;   }   /* select the palette which was loaded from the datafile */   set_palette(datafile[THE_PALETTE].dat);   /* aha, set a palette and let Allegro convert colors when blitting */   set_color_conversion(COLORCONV_TOTAL);      /* display the bitmap from the datafile */   textout(screen, font, "This is the bitmap:", 32, 16, makecol(255, 255, 255));   blit(datafile[SILLY_BITMAP].dat, screen, 0, 0, 64, 32, 64, 64);   /* and use the font from the datafile */   textout(screen, datafile[BIG_FONT].dat, "And this is a big font!", 32, 128,	   makecol(0, 255, 0));   readkey();   /* unload the datafile when we are finished with it */   unload_datafile(datafile);   return 0;}END_OF_MAIN();


As you can see you first need to declare your datafile:
DATAFILE *data;
(in your case it's data instead of datafile)

It seems to me that you didn't do that globally (meaning declared outside of the main function).

The next step after that is to load the actual file into the variable. That's done with
data = load_datafile("yourfilename.dat");
where you replace yourfilename.dat with whatever your filename is. Do this before you call that drawAll() function.
Advertisement
well i think i got that problem fixed but there is one error left that says there is an invalid convertion from BITMAP* to void

error: invalid conversion from `void*' to `BITMAP*'
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
If you're casting properly, that shouldn't happen.

draw_sprite(screen, (BITMAP *)data[THE_IMAGE].dat, x, y);

Jesus saves ... the rest of you take 2d4 fire damage.

#include "main.h"#include "allegro.h"int main(int argc, char *argv[]){   DATAFILE *datafile;   char buf[256];   allegro_init();   install_keyboard();    if (set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0) {      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);      allegro_message("Unable to set any graphic mode\n%s\n", allegro_error);      return 1;   }   /* we still don't have a palette => Don't let Allegro twist colors */   set_color_conversion(COLORCONV_NONE);   /* load the datafile into memory */   replace_filename(buf, argv[0], "datafile.dat", sizeof(buf));   datafile = load_datafile(buf);   if (!datafile) {      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);      allegro_message("Error loading %s!\n", buf);      return 1;   }   /* select the palette which was loaded from the datafile */  // set_palette(datafile[THE_PALETTE].dat);   /* aha, set a palette and let Allegro convert colors when blitting */   set_color_conversion(COLORCONV_TOTAL);      /* display the bitmap from the datafile */   textout(screen, font, "This is the bitmap:", 32, 16, makecol(255, 255, 255));   blit(datafile[building_red].dat, screen, 0, 0, 64, 32, 64, 64);   /* and use the font from the datafile */  // textout(screen, datafile[BIG_FONT].dat, "And this is a big font!", 32, 128,//	   makecol(0, 255, 0));   readkey();   /* unload the datafile when we are finished with it */   unload_datafile(datafile);   return 0;}END_OF_MAIN();


heres the file thats having the problems i think it SHOULD compile fine but its not (is this a problem with dev-cpp im useing 4.9.9.0)
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
Just as 23 said, you've got to cast the data object to a BITMAP*, like this:
// This doesn't work because you haven't cast the pointerblit(datafile[building_red].dat, screen, 0, 0, 64, 32, 64, 64);// This will workblit((BITMAP *)datafile[building_red].dat, screen, 0, 0, 64, 32, 64, 64);


If you already did that, then tell us your error message. Your code looks fine otherwise...

-Auron

This topic is closed to new replies.

Advertisement