Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Structures??


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 Violento   Members   -  Reputation: 122

Like
Likes
Like

Posted 22 July 2001 - 07:48 AM

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??

Sponsor:

#2 Sickilla   Members   -  Reputation: 122

Like
Likes
Like

Posted 22 July 2001 - 12:41 PM

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

#3 Violento   Members   -  Reputation: 122

Like
Likes
Like

Posted 23 July 2001 - 03:33 AM

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"?

#4 evaclear   Members   -  Reputation: 162

Like
Likes
Like

Posted 23 July 2001 - 03:43 AM

Your still not naming the structure.

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

player myPlayer;

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

#5 Sandman   Moderators   -  Reputation: 2136

Like
Likes
Like

Posted 23 July 2001 - 04:18 AM

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)



#6 Violento   Members   -  Reputation: 122

Like
Likes
Like

Posted 23 July 2001 - 04:34 AM

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!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS