Trouble with pointers

I am writing a game that is heavy on pointers. I have a function that is supposed to assign pointers to nodes, like so:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
void setPointers(world map[]){

	for(int i = 0; i < 20; i++){
		if(i % 4 != 3){
			map[i].east->map[i + 1];
		}
		if(i % 4 != 0){
			map[i].west->map[i - 1];
		}
		if(i < 16){
			map[i].south->map[i + 4];
		}
		if(i > 3){
			map[i].north->map[i - 4];
		}
	}
}


I then attempt to move the player's position according to those pointers:

1
2
3
4
5
6
7
8
9
10
11
void playerPos(world *playerLoc, world map[]){

	playerLoc = &map[17];

	cout<<playerLoc->location;

	playerLoc->map[17].north;

	cout<<playerLoc->location;

}


Line 5 prints out the correct value. Line 9 prints the same data, though.

The program doesn't crash but I can't seem to move the current position. I assume I am doing something blatantly wrong here that will hopefully be an easy fix.

If anybody can help me I'd really appreciate it. If you need more of my code let me know.
map[i].east->map[i + 1]; statement has no effect. I suppose that you want map[i].east = map[i + 1]; playerLoc->map[17].north; same here
I've tried that. under map[i + 1] a message comes up saying that there is no suitable conversion function to change from world to *world (that's the type of the array).

If I write *map[i + 1], it says no operator matches the operands... Should I try it on the left half, the program crashes.

EDIT: Fixed. All it needed was map[i].east = &map[i + 1]; for each line. The pointers are working as they should now.
Last edited on
The thing is the '->' operator says "Take the data this pointer on the left refers to and give me this member on the right from it". It doesn't change the value of playerLoc, the '+1' is an offset, which is what I think ne555 is trying to tell you. Where as his code actually reassigns a value to "map[i].east".

Topic archived. No new replies allowed.