Passing multiple variable types to a function

I'm writing a little game, and to save the game data I would like to take the variables that I have in main and send them to a save game function in a class.

Currently to save a user I set the file name as the username, and then the contents are, string (password), int, int, int.... char[], char[].

Is it possible to send multiple variable types through a function, or is there a better way of solving this issue.

Saving function.
1
2
3
4
5
6
7
8
  void Save::SaveGame(string userName, string password, int baseDamage, int hp, int xp, int mapLevel, char abilities[], char backPack[] )
{
	ofstream writer(userName);
	writer << password << " " << baseDamage << " " << hp << " " << xp << " " << mapLevel << " "
		<< abilities[0] << " " << abilities[1] << " " << abilities[2] << " " << abilities[3] << " "
		<< backPack[0] << " " << backPack[1] << " " << backPack[2] << " " << backPack[3] << " " << backPack[4] << " " << backPack[5] << " "
		<< backPack[6] << " " << backPack[7] << " " << backPack[8] << " " << backPack[9];
}
I would create a class called player or user that would store all the infos and would be able so load and save itself from a stream or file.
i agree with Thomas, you can pass as many variables as you want through a function but using a class or struct makes this much easier to keep track of
I will add to what was already said.

Make a class that maintains your game's state. Give it a method that saves the game's state to disk. (And a method that can load the saved state.) Use the class to maintain the state of the game while playing.

Hope this helps.
Topic archived. No new replies allowed.