Hey all,
I was wondering if there was a way to create a new .txt file every time the game runs? I am able to write the data I want to a .txt file but it always adds onto the same file when I play my game. What I am looking for is when ever I start the game it will create a new .txt file and save all that data for that instance only.
Here is my current code:
void addItemsToLog()
{
File.AppendAllText("OutputLogs/outputLog.txt", "
" + "
" + "Player 1 Stats: ");
File.AppendAllText(“OutputLogs/outputLog.txt”, "
" + “Player 1 Money: $” + player1Money);
foreach (string property in player1PropertyOwned)
{
File.AppendAllText("OutputLogs/outputLog.txt", "
" + "Player 1 owns: " + property);
//yield return null;
}
File.AppendAllText("OutputLogs/outputLog.txt","
" + "
" + "Player 2 Stats: ");
File.AppendAllText(“OutputLogs/outputLog.txt”, "
" + “Player 2 Money: $” + player2Money);
foreach (string property in player2PropertyOwned)
{
File.AppendAllText("OutputLogs/outputLog.txt", "
" + "Player 2 owns: " + property);
}
}
This will give me all the data in a file named “outputlog.txt” but what I am trying to do is when I run the game a second time it will save that to “outputlog(1).txt” for example.
Thanks in advance.