Skip to main content
gamedev.net
🔒 Locked

Invalid Array Subscript Error

Started by CyberSlag5k 3 replies 850+ views
Original Post
CyberSlag5k
CyberSlag5k
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...
Without order nothing can exist - without chaos nothing can evolve.
BriTeg
BriTeg
Need more code. How did you declare those variables?
Brianmiserere nostri <font color=#BC
CyberSlag5k
CyberSlag5k
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...
Without order nothing can exist - without chaos nothing can evolve.
BriTeg
BriTeg
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]
Brianmiserere nostri <font color=#BC
CyberSlag5k
CyberSlag5k
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...
Without order nothing can exist - without chaos nothing can evolve.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.