- Home /
PlayerPrefs string variables
Hi everyone! Well I've been looking for the way of making a PlayerPrefs Save system that allows the user (in the Editor) setting the name of each Pref (example: "level1", "level2", "level3"...). With this I could have a simple script and depending in what level I am, I could set the name of the level and then saving the highscore of each one. It's more or less like this:
public string lvlNumb;
void OnTriggerEnter{
PlayerPrefs.SetInt("lvlNumb", 1234);
}
I know it is possible to set the value with any int variable, but is thera any way to change the "string" from the editor?
I hope anyone can understand my trouble and can help me.
Thanks a lot.
Albert.
Answer by whydoidoit · Oct 16, 2013 at 04:47 PM
You just want to do:
PlayerPrefs.SetInt(lvlNumb, 1234);
No quotes!
Sorry I took the code copy/pasted and I forgot to delete them. I have it like that, without quotes, and the console outputs this message:
CS1502: The best overloaded method match for `UnityEngine.PlayerPrefs.SetString(string, string)' has some invalid arguments
Thanks for your atention, do you have any idea?
Scorpox: The error is complaining about a argument inside a SetString function, not a SetInt function (which your sample code displays).
Does your code look like this?
public string lvlNumb;
void OnTriggerEnter{
PlayerPrefs.SetString(lvlNumb, 1234);
}
If yes, then you need to put a string argument in to the function call ins$$anonymous$$d of the 1234 or go back to the SetInt function like whydoidoit showed you :)
That really looks like it should be SetInt. Otherwise 1234.ToString()
Solved! :D Tanks a lot guys, I was getting crazy with this, I spent a week to understand the playerprefs, don't ask me why haha... Sometimes the solution is in front of you and you cannot see it. Thanks again! See you in the forum :D
Your answer
Follow this Question
Related Questions
PlayerPrefs Int to Float 1 Answer
Saving a Dictionary To PlayerPrefs 2 Answers
Convert class of int vars into an array 0 Answers
How to send user file to update already compiled game? 0 Answers