Reputation: 3563
I make saveGame function and I have 6 slots for saving. How can I say, to which slot should I save data? Should I create variables for each of 6 slots
private int currentActiveSlot;
private int latestSaveSlot;
const int _numberOfSlots = 7;
string[] dateTime = new string[_numberOfSlots];
int[] actNumber = new int[_numberOfSlots];
int[] stepNumber = new int[_numberOfSlots];
int[] transformPositionX = new int[_numberOfSlots];
int[] transformPositionY = new int[_numberOfSlots];
int[] transformPositionZ = new int[_numberOfSlots];
int[] transformRotationX = new int[_numberOfSlots];
int[] transformRotationY = new int[_numberOfSlots];
int[] transformRotationZ = new int[_numberOfSlots];
void Start()
{
latestSaveSlot = PlayerPrefs.GetInt("latestSaveSlot");
}
public void ButtonSave()
{
// How to say, to which slot should I save?
latestSaveSlot = currentActiveSlot;
PlayerPrefs.SetString("date time", "");
PlayerPrefs.SetInt("act number", 0);
PlayerPrefs.SetInt("step number", 0);
//..
PlayerPrefs.Save();
dateTime[latestSaveSlot] = PlayerPrefs.GetString("date time");
}
public void ButtonLoad()
{
dateTime[currentActiveSlot] = PlayerPrefs.GetString("date time");
actNumber[currentActiveSlot] = PlayerPrefs.GetInt("act number");
stepNumber[currentActiveSlot] = PlayerPrefs.GetInt("step number");
//..
}
Upvotes: 0
Views: 348
Reputation: 6123
The most basic approach (not the best one, I know) would be to add the slot's index directly into the PlayerPrefs' key. You just have 6 of them, so the number of keys will remain acceptable. Something like this:
public void ButtonSave()
{
// How to say, to which slot should I save?
latestSaveSlot = currentActiveSlot;
PlayerPrefs.SetString("date time" + latestSaveSlot, "");
//...
And, similarly for the loading phase.
public void ButtonLoad()
{
dateTime[currentActiveSlot] = PlayerPrefs.GetString("date time" + currentActiveSlot);
//...
Upvotes: 1
Reputation: 2929
If I understood correctly, then I would do the following:
Each Save slot would have the "SavedOn(DateTime)", "SavedById (int-> user that did the action of saving), "".
Then, when you want to make a new saving, I would search first for the slot that is "null" (order by id asc), if there is none, I would display the oldest one and ask the user if he wants to rewrite it (by losing the old data and saving the new one).
Is this what you are looking for?
Upvotes: 1