- Home /
Save Function not working
I have a save function that for some reasons brings up a Compile error.
public static void saveProgress(string saveName){
BinaryFormatter bf = new BinaryFormatter ();
string tempString = Application.persistentDataPath + "/" + saveName + ".dat";
FileStream fs = File.Create(tempString, FileMode.Create);
bf.Serialize (fs, GameState.getInstance());
fs.Close ();
}
The error message I get is this:
Assets/SaveGame.cs(22,38): error CS1502: The best overloaded method match for `System.IO.File.Create(string, int)' has some invalid arguments
But it's strange because I'm passing in a string and what I assume to be an int in the from of FileMode.Create. Any help would be greatly appreciated.
Answer by tanoshimi · Jan 04, 2014 at 05:14 PM
No, you're passing in a string and a FileMode...
The second parameter passed to File.Create needs to be an int representing the number of bytes to write to the file: http://msdn.microsoft.com/en-us/library/981h90e5%28v=vs.110%29.aspx
You're right, but the second parameter is just the read-write-buffer size. You worded it a bit strange ;) If you don't want to explicitly set the buffersize you can simply omit the parameter since File.Create has several overloads
Bunny, that link was very helpful! I think the problem I had was due to me reading an out of date tutorial - I'm assu$$anonymous$$g .Net has updated it's API since it's publication.
@tanoshimi, you're right. File$$anonymous$$ode.Create returns an enum rather than an int and the current API for File.Create doesn't accept that particular grouping of arguments.
As I mentioned, I've been reading out of date material. >_>
Your answer

Follow this Question
Related Questions
Multiplayer Persistant Gaming 1 Answer
Have objects persist in one scene, and not across all scenes? (C#) 0 Answers
Get Reliable Instance ID 0 Answers
Make changes in prefabs persistent. 2 Answers
[C#]Persistent Saving and Loading 1 Answer