Expected an Expression in array

Hi, I'm working on a game for the iphone with dragonfire and I am a complete noob to c++. I'm trying to make the meerkat appear at a random hole. I don't know if I'm going about it the right way, but at the moment I'm getting this error at this point:

kathole[5] = {holea, holeb, holec, holed, holee};

the { is underlined in red and says 'Error expected an expression'

another thing is, if I declare the array before the appmain bit then I don't get the error above, but the images hole1 etc. don't load, only a red square appears which I think is what happens if the image file can't be found.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
  #include "DragonFireSDK.h"



//declair 5 different positions
int katx[5] = {217, 428, 213, 377, 111};
int katy[5] = {8,35,66,142,249};
int randscat;
int LogoImage;
int LogoView;
int holea;
int holeb;
int holec;
int holed;
int holee;
char kathole[5];
int holeview1;
int holeview2;
int holeview3;
int holeview4;
int holeview5;
char dispcat;
char choose;

void AppMain()
{
	
	randscat =Random(5);
	// View iPhone Simulator Landscape
   LandscapeMode();
	// Application initialization code goes here.  Create the items / objects / etc.
	// that your app will need while it is running.
	LogoImage=ImageAdd("Images/bg.png"); // file location: Debug/Assets/Images/Logo.png
	holea=ImageAdd("Images/hole1.png");
	holeb=ImageAdd("Images/hole2.png");
	holec=ImageAdd("Images/hole3.png");
	holed=ImageAdd("Images/hole4.png");
	holee=ImageAdd("Images/hole5.png");
	kathole[5] = {holea, holeb, holec, holed, holee};
	LogoView=ViewAdd(LogoImage,0,0);
	choose = kathole[randscat];
	holeview1=ViewAdd(choose,katx[randscat],katy[randscat]);
}

void AppExit()
{
	// Application exit code goes here.  Perform any clean up your app might 
	// need to do in the event of interruption by a phone call or the user
	// pressing the Home button, or some other event that would cause your
	// application to terminate.
}
kathole[5] = {holea, holeb, holec, holed, holee};
the { is underlined in red and says 'Error expected an expression'


After the initial declaration of kathole which defines the number of elements kathole consists of, further mentions of kathole with a subscript refer to individual elements of kathole. Valid indices for kathole are 0 to 4, since it has 5 elements, which means that kathole[5] is a nonexistent element. And, were it a valid index, it would not make sense to set a single char to: {holea, holeb, holec, holed, holee}
One thing I notice is that kathole is defined as an array of five characters; but you're initializing the array with integers. And the array can't be initialized in this manner unless it is used in the declaration.

So,

1
2
3
4
5
6
7
8

holea = ImageAdd( "Images/hole1.png" );

/*    etc.    */

int kathole[] =
    { holea, holeb, holec, holed, holee };
Thanks for replies, I think it is the int thing, but I have done it a different way now. I thought that "Images/hole1.png" was a string. How is it an int?
heldenbrau wrote:
I thought that "Images/hole1.png" was a string. How is it an int?
Because you wrote this:
11
12
13
14
15
int holea;
int holeb;
int holec;
int holed;
int holee;
Last edited on
Topic archived. No new replies allowed.