Jump to content
  • Advertisement

Archived

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

Violento

Structures??

This topic is 6238 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Your still not naming the structure.

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

player myPlayer;

myPlayer.x = blah blah;
myPlayer.y = blah blah;

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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!