Saving slot with specified ID

(Maylin Liaran) #1


In my project I want to use specified number of slots. Each ones ID has been assigned to [0;7]

Let’s say slots 0, 1 and 2 are already taken.
So… When I Try to Persist.Instance.Save(ID) it overrides file if a record of such a slot already exists in, and that part is ok. But when I try to save a new slot with ID 5, it creates file, but does not register it to, thus I cannot load from this slot.

The tooltip of Persist.Instance.Save(ID) says “If id=“n” means to add a new slot”, but it creates slot with “nextSlotId”: 3 taken from What if I want to create slot with ID 5, without having ID 4?

I assume that in order to implement this I need to modify Persist.Instance.Save(ID) method, but it comes as a part of dll, so I cannot?

(Leslie Young) #2

Sorry this is such a hassle. I did not make BGS to be an API/ framework so I did not expect devs to access it its core systems via script. But I am sure it is possible to achieve what you want though.

The ID you feed Save() must be one that exists. If you pass “n” then it means a new save with a new ID should be created. The ID returned by this is what you should keep around if you want to auto-save back to that specific slot during a session.

Do not think of the slot ID as indices. The idea with the save system is not that there are static slots and that the player may even delete older saves. So, internally the save system will keep track of save slot IDs to generate and the easiest way is to simply increment a counter without worrying whether older IDs get destroyed or not.

To find out what IDs exist you call List<PersistSlotInfo> slots = Persist.Instance.Slots();
Now you know what saves actually exist and can update the buttons on the save or load UI with the correct info. The included save/load panels will show you how I did this. Assets\Tools\BGS\scripts\GUI\Panels\Persistence

But they do not present a static set of slots to the player and possibly why you are not using them? To do that can still be achieved but one drawback is that you will not know an exact order to show used slots. You can not for example show that the player chose to use slot 2 if he did not make a save to 1 yet.

In another project I have only 3 save slots. The player can click on any of the 3 “new game” buttons to create a save ID that will be used to create auto-saves of that game session but when it comes to loading the player will see slots are ordered from top-down to show used first and empty slots after. They are date stamped though so that helps identify which saves are which.

Here is an example of a panel which allows the player to either choose to start a new game or to load and continue an existing save. In this game the player do not get to save. All saves are done automatically by the game when needed.You will note when a “new game” is chosen the player is taken to a character creation panel. After that the call the game will create a new save via Save(“n”) and then the returned ID is tracked by the game and reused when saving. There is also a CreateNewSaveSlot() which can be used.

LoadGamePanel.cs (3.3 KB)

These show load/save panels that appear to have static slots. Note though that used slots are ordered so that they appear 1st since I can not truly tell which should have been first or second if the player chose to create a new game on the second slot rather than the first, first. The load game is very similar to the preious example but in this case I do not track the “new game” ID.

SaveGamePanel.cs (2.2 KB)
LoadGamePanel.cs (3.2 KB)