Jump to content
  • Advertisement

Archived

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

RoTTer

Need some help with structs

This topic is 6920 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

Hello! It''s been a while I dont post/read here... was somewhat away from programming, but now I hope to be back for some time at least. Nice to see ya''ll again =]. I need to make a struct that has other structs inside it. Im not sure how to explain (but Im pretty sure it exists and is widely used), so Ill give an example. It would be accessed like this : object[10].property[3].active = 1; player[2].status.hp.poisoned = 0; Can someone clear this up to me? Thanks a lot Oh, and please dont say "Use classes! Structs suck!" cause Im not really willing to stop and learn it and then apply. I want to do it now, and Im somewhat used to structs, so Ill stick with it for now. Thanks a lot, -RoTTer

Share this post


Link to post
Share on other sites
Advertisement
Here''s how you can do something similar to your first example:

struct prop{
int active;
};

struct obj{
struct prop property[5];
};

struct obj object[20];

int main(void)
{
object[10].property[3].active = 1;
}


I hope that helps!

Share this post


Link to post
Share on other sites
Woa, thanks a lot!
It worked perfectly! Just as I wanted it to be :>

Thanks again, and sorry for the delay answering =]

Cya,-
RoTTer

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!