A struct is a collection of related variables. You can define a struct as a variable type. Then you can make as many of those as you want. A struct's variables are accessed with a '.' after the struct name. If you have a pointer, use '->' instead. This is exactly what an Actor is. When you just use 'x' or 'textNumber', for example, you access the event actor's variables for those values. Bu when you access another actor's variables, you use 'actor.y' or 'actor.angle'. In this case, 'actor', the name of the Actor in question, is a struct. Using '.', you are accessing it's values.
Some functions in GE (getclone, CreateActor, getactor etc.) return a pointer to an Actor (Actor *). This means you can store a reference to the original Actor, and access it's current values, and change them. To do that, use '->' (eg. actor->animpos = 36). To set an actor (or any other variable) as a pointer, use '&'. At times it can get confusing what you're working with, and whether you need to use '*' or '&'. When a pointer, use '*'. When assigning a pointer, use '&'. WHen changing a pointer, use '*'. For instance:
- Code: Select all
Actor *pActor = &ball.
pActor->xvelocity *= -1;
or with an int:
- Code: Select all
int *pInt = &yscreen;
*pInt+= 50;
Like this, it is pointless. It comes handy when you want a parameter in a function, or if you want to store information in another location. In the above example, if I were to just make a separate int, and set it to yscreen, when I changed it, it would not change yscreen.
To define a struct, use:
- Code: Select all
typedef struct
{
int x;
int y;
}coordinate;
In this way, you can make other useful things. For the territory example, you might do this:
- Code: Select all
typedef struct
{
int attack;
int defense;
char owner;
char border;
int x;//the x coordinate in the board array
int y;//the y coordinate in the board array
}territory;
You can then make a 2d array of territories:
- Code: Select all
territory board[100][100];
If you wanted to store a territory (such as in a temporary list) you would make a pointer:
- Code: Select all
territory *tempList[10000];
int i;
int j;
int lPos = 0;
for (j = 0; j < 100; j ++)
{
for (i = 0; i < 100; i ++)
{
if (board[i][j].border)
{
tempList[lPos] = &board[i][j];
lPos ++;
}
else if//check adjacent territories...
}
}
In this case, you might be able to combine both if statements. You'd then need somewhere to store priority and action. You could even make another struct which contains a territory:
- Code: Select all
typedef struct
{
int priority;
char moveType;
territory *location;
}move;
Then in the above example you'd change it to:
- Code: Select all
move tempList[10000];
//...
tempList[lPos].location = &board[i][j];
//...
\
to get information from the territory, you'd do something like this:
- Code: Select all
tempList[i].location->defense
Of course, 'i' would be changed to whatever index you want.
Hope that helps a bit. If you have any further questions, ask them, I won't complain (I might get mad and not answer, but I won't complain

).