GP32 Passing Structs With More Than 1 Dimension


ConsoleTom

Member
Joined
Dec 4, 2003
Messages
106
Age
47
Location
Germany
Website
Visit site
Hi !

I have a struct

struct LMap
{
unsigned short nTile;
unsigned short nState;
}

then i define a variable

struct LMap sLevel1Map[32][32];

and i would like to create a subroutine:

void PlayLevel( :angry: :angry: :angry: )

Now, how do i pass my sLevel1Map to the subroutine. Using pointers, but how ? I tried around but got error-messages about incompatible pointers or the passed data was wrong.

I would like to know,

- how to call the routine [ PlayLevel (&sLevel1Map) ]
- how the variable is declared in the sub [ void PlayLevel(struct LMap * PlayLevel) ]

Please help me soon. I can't continue coding my game !!!

Greetings

Tobias
 
Code:
void PlayLevel(struct LMap * PlayLevel)
That part is right.

Code:
PlayLevel (&sLevel1Map)
That part isn't. You need to give it straight to the function like this:
Code:
PlayLevel(sLevel1Map);
Attempting to case it into an array with & or upcasting it like
Code:
PlayLevel((struct)sLevel1Map);
only confuses the compiler.

I think :unsure:
 
What Blah said is correct.

Into the function PlayLevel you can access to the elements of the struct in this way:

Code:
sLevel1Map->nTile = x;
sLevel1Map->nState = y;

Regards
 
I'm not really sure that it is what he wants as with this solution you loose the information of one dimension, and so, to be able to access any tile in the map, you must make the calculations yourself.

I think a better solution for this case, if the map is always 32 tiles (height/width?) is this:

Code:
void PlayLevel(struct LMap levelMap[][32])
{
  // Now we can access any tile as easy as outside the function
  levelMap[n][m].nTile = 0;
  levelMap[n][m].nState = 0;
}

Oankali
 
In things like this, I would also suggest using a typedef to make things more readable:

typedef struct
{
unsigned short nTile;
unsigned short nState;
} LMap;

LMap sLevel1Map[32][32];

void PlayLevel(LMap levelMap[32][32]) // or whatever
{
}
 
Back
Top