Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » nested datafiles

This thread is locked; no one can reply to it. rss feed Print
nested datafiles
Rick
Member #3,572
June 2003
avatar

Someone has to know this. I'm trying to get to the bitmaps from my datafile and it's 3 layers nested.

for example

LION.dat
    STAND.dat              "STAND"
        WEST.dat           "WEST"
            001.bmp
            002.bmp
        EAST.dat            "EAST"
            001.bmp
            002.bmp

I load LION.dat with load_datafile() and that works. I then build the path to the animation and direction datafile I want. ie.

DATAFILE* object = load_datafile("lion.dat");
DATAFILE* m_direction = find_datafile_object( object, "STAND/WEST" );

m_direction seems to come back with the West datafile inside the Stand datafile. I know this because the following does come back with "WEST":

      finalPath = get_datafile_property(m_direction,
                                   DAT_ID('N','A','M','E'));

I want to loop through the m_direction datafile to get each bitmap in that direction datafile. Knowing what is above how would I go about doing that? Thanks.

========================================================
Actually I think I'm a tad ugly, but some women disagree, mostly Asians for some reason.

Jonatan Hedborg
Member #4,886
July 2004
avatar

Not exactly sure, but acording to the manual, something like this might work:

DATAFILE* object = load_datafile("lion.dat");
DATAFILE* m_direction = find_datafile_object( object, "STAND/WEST" );
BITMAP *list[ANIM_COUNT]; //or whatever
for(int i=0; i<ANIM_COUNT; i++)
  list<i> = (BITMAP*) m_direction<i>.dat;

Untested code, naturally ;)

Rick
Member #3,572
June 2003
avatar

If "EAST" is the first datafile within the sit datafile, then should these 2 lines of code be equal?

east = find_datafile_object( sit, "EAST" );
east = (DATAFILE*) sit[0].dat;

I would say yes, but they are not. If I then take east and try to loop through it while != DAT_END, the 2 ways above give me different results. Why would that be?

[EDIT]
I got it, and I'll post it here for future reference. The key is:

Quote:

Returns a pointer to a single DATAFILE element whose `dat' member points to the object, or NULL if the object could not be found.

east->dat points to the datafile object I want.

((DATAFILE*)east->dat)<i>.dat

========================================================
Actually I think I'm a tad ugly, but some women disagree, mostly Asians for some reason.

Go to: