Is there a way to save in a text based game through the MSDOS window? I want to be able to save the variables that store the mana, health, ect of a player.
Shadoninja 0 Light Poster
Recommended Answers
Jump to Post— Salem 6,009Sure.
All you need to decide is which variables you have in your game which are necessary to restore the state of the game.
Jump to Post— CoolGamer48 65You would use ifstream to read data (much like cin), and ofstream to write it (like cout). (note: cout and cin are objects of classes that are already made. ifstream and ofstream are actual classes).
To write data:
ofstream fout("file.sav"); fout << health << "\n" << …
Jump to Post— ivailosp 11or make one class game_state and then output.write(&game_state, sizeof(game_state)) and to restore input.read(&game_state, sizeof(game_state))
All 11 Replies
Salem 6,009 Posting Sage
CoolGamer48 65 Posting Pro in Training
ivailosp 11 Junior Poster
Shadoninja 0 Light Poster
Salem 6,009 Posting Sage
Shadoninja 0 Light Poster
CoolGamer48 65 Posting Pro in Training
Shadoninja 0 Light Poster
kidprogrammer 0 Newbie Poster
Shadoninja 0 Light Poster
kidprogrammer 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.