🎉 Celebrating 25 Years of GameDev.net! 🎉
Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!
Structures??
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??
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
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
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"?
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"?
Your still not naming the structure.
struct player
{
int x,y;
int speed;
};
player myPlayer;
myPlayer.x = blah blah;
myPlayer.y = blah blah;
struct player
{
int x,y;
int speed;
};
player myPlayer;
myPlayer.x = blah blah;
myPlayer.y = blah blah;
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)
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)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement