Archived

This topic is now archived and is closed to further replies.

Invalid Array Subscript Error

This topic is 5023 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am currently working on a gba application and am attempting to my sprite color palette and data into OAM. However, when I compile I get the error: invalid types ''int[int]'' for array subscript The trouble areas of my code are:
for(int i = 0; i < 128; i++)
	OAMdata[i] = mySpriteData[i]; //line 77


for(int i = 0; i < 256; i++)
{
	paletteMem[i] = FFPalette[i]; //line 81

	OBJPaletteMem[i] = mySpritePalette[i]; //line 82

}

What is odd is that I get that error twice, in lines 77 and 82, but not in line 81 as well. As similar as these three lines are, I would think that it would show up in all three. The only difference is that FFPallette is the palette for my background image and not a sprite as the other two are, but both types are defined the same way. Anyone have an idea of what''s going on here? Thanks When you find yourself in the company of a halfling and an ill-tempered Dragon, remember, you do not have to outrun the Dragon...

Share this post


Link to post
Share on other sites
Right right, silly me.

#define OBJPaletteMem (u16*)0x5000200
#define OAMdata (u16*)0x6100000

u16* paletteMem = (u16*)0x5000000;

the defines are in included header files, paletteMem in my main.cpp

FFPalette, mySpriteData, and mySpritePalette are all created by the conversion program I use and are defined as:

const u16 mySpriteData[] = { /*stuff*/ }
const u16 mySpritePalette[] = { /*stuff*/ }
const u16 FFData[] = { /*stuff*/ }

When you find yourself in the company of a halfling and an ill-tempered Dragon, remember, you do not have to outrun the Dragon...

Share this post


Link to post
Share on other sites
I think the problem is these two lines:

#define OBJPaletteMem (u16*)0x5000200
#define OAMdata (u16*)0x6100000

As defines, the compiler is putting those directly into the code that uses them. Thus your code becomes:

(u16*)0x6100000[ i ] = mySpriteData[ i ]; //line 77

That's probably getting interpreted as (u16*)(0x6100000[ i ]), which is not valid, subscripting a memory address directly like that.

I suspect doing either of the following would work:

#define OBJPaletteMem ((u16*)0x5000200) // note the added brackets
#define OAMdata ((u16*)0x6100000)

or

u16* OBJPaletteMem = (u16*)0x5000200;
u16* OAMdata = (u16*)0x6100000;

Try either of those, and let me know.

[edited by - BriTeg on April 16, 2004 2:22:50 PM]

[edited by - BriTeg on April 16, 2004 2:24:44 PM]

Share this post


Link to post
Share on other sites
Great! The first one did the trick. Thanks alot, BriTeg.

When you find yourself in the company of a halfling and an ill-tempered Dragon, remember, you do not have to outrun the Dragon...

Share this post


Link to post
Share on other sites