Archived

This topic is now archived and is closed to further replies.

Violento

Structures??

Recommended Posts

I have a problem with structures in my game. My project has these files vars.c and vars.h, where i declare stuff. I have the player''s structure in the vars.h like this... typedef struct{ int x,y; int speed; (and all the other player-stuff..) }player; And in the vars.c... static player pl; pl.x = 16; pl.y = 16; pl.speed = 1; I get the error "parse error before `.´" at the pl.x point. So my point is to add those values to the player structure, but i can see that i''m doing something wrong. I''m confused cause it worked before when i was programming with one .c-file only. So if somebody could tell me how to do this??

Share this post


Link to post
Share on other sites
your structure doesn''t have a name try changing it to this:

typedef struct player
{
int x,y;
int speed;
(and all the other player-stuff..)
}player;

also, if you are using C++, i reccomend classes.




X4J

Share this post


Link to post
Share on other sites
Didn''t work..
Even when i tried it as simple as this...

vars.c :

struct{
int x,y;
int speed;
}pl;

pl.x = 16;
pl.y = 16;
pl.speed = 1;

...it gives me the same error. I guess i should put something in front of "pl.x = 16"?

Share this post


Link to post
Share on other sites
Shouldnt need to name the structure... the original code looks like it should work....

Here are a few possibilities (I apologise if any of these are insultingly obvious, but sometimes even the best coders can overlook stupid mistakes)

1. You are actually #include ing the header arent you?

2. The references to pl.x and so on must be inside a function. If you want to initialise a global with certain values, use the {} notation...

static player pl = {16,16,1,blah blah};

3. Do you have any other definitions in the .h file? make sure they are all syntactically correct (no missing ;''s for example)

Share this post


Link to post
Share on other sites
Hey! That "static player pl = {16,16,1,blah blah};" worked!

Well, that was new to me =). That''s why i posted this at the newbie section. I really should get some tutorials about this "multi-file"-programming.

Thanks!

Share this post


Link to post
Share on other sites