Jump to content
  • Advertisement

Archived

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

Squirell

Variables across multiple sources

This topic is 5323 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 using the same variables in to different sources of the same project in Dev C++. Lets say i have to .cpp files, ai and game. How can i use variables from ai in game or game in ai. I can get functions to work, just not variables that i declare at the top of the source.

Share this post


Link to post
Share on other sites
Advertisement
Google ''extern tutorial c'' or something like that for more info. Really, it is best that you don''t focus much on that. If you are going to be using c++ you really will need to learn a bit of OOP.

Share this post


Link to post
Share on other sites
Wanting to share isolated variables across source files is not a sign of doing OOP. You want to be specifying an AI class and a Game class, and create new AI instances within your Game logic or vice-versa. :/

Share this post


Link to post
Share on other sites
i know what oop is, im curious about something DIFFERENT. But creating a game and ai class would be a way of doing things
thanx

Share this post


Link to post
Share on other sites
in your header, declare the variable as:
extern float poop;
or whatever type/name you want.

then in the cpp of that header, make the global variable:
float poop;

then in the other cpp, include the previous header and you can use poop to your delight.

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!