Sign in to follow this  

Loading globals from a txt file ()

Recommended Posts

Hello all! I am making a game for my school project although my questions are about C++ in general. In the beginning of my programm I declare my globals, some of them are arrays of class objects I made for the game (like coins). The amount of objects in the levels of the game differ and I want to repeatedly load this main-game file (.cpp) with different txt files per level. How to declare my globals from a txt file? I want (if possible) to load this main-game file after a choice is made from the menu (like 1 or 2 players, credits etc.). And if you enter lvl2 a new txt file must be loaded into the main-game file's globals. Its rather difficult, cause its a mix of C++ questions && game-programmingstructuredesignquestions *bluh*

Share this post

Link to post
Share on other sites
from what i've read, it sounds like you would have to just have a long coded functions that reads the file and inputs each value into every value individually.

fake code:

ifstream fin;

fin >> coin.value;
fin >> coin.numberofCoins;
fin >> numberofLives;
fin >> numberofEnemies;
fin >> nameofLastBoss;

hopes that helps a little...

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this