I'm using this tutorial (https://adventurecreator.org/tutorials/custom-save-game-labels) to create custom save game names that the player can then edit, that's working very well.
I would like, on the Load menu, in the saveslist, for each button to display not only the name but the content of a variable from that save file (in this case, the hours played.) Currently I'm saving that information into the save name itself, but that information would become out of date the next time the player used the same save file. Ideally I'd love to display the info as a second, smaller label under the save file name. Is there a way to access that information, or run an actionlist when the button is being created that can do that? Thanks!
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
It requires scripting, but it's possible.
Is this a Global Variable? Essentially, you'd need to extract the variable data for each save file as the Load menu is populated, and then display that in a Text box associated with that save slot.
The SaveSystem script's ExtractSaveFileVariables function can be used to extract variables from a save file.
You'll need to use Unity UI so that you can attach such a script to each Text box.
Something along these lines ought to do it:
I'm having some issues with this script, it's throwing a few errors -
Assets\DisplaySaveVariable.cs(19,31): error CS1061: 'MenuSavesList' does not contain a definition for 'GetSlotIndex' and no accessible extension method 'GetSlotIndex' accepting a first argument of type 'MenuSavesList' could be found (are you missing a using directive or an assembly reference?)
Assets\DisplaySaveVariable.cs(20,39): error CS1061: 'MenuSavesList' does not contain a definition for 'GetSaveFile' and no accessible extension method 'GetSaveFile' accepting a first argument of type 'MenuSavesList' could be found (are you missing a using directive or an assembly reference?)
Assets\DisplaySaveVariable.cs(21,20): error CS1501: No overload for method 'ExtractSaveFileVariables' takes 2 arguments
What's your AC version? It should compile with the latest release.
Has that way of Getting the real SaveID from an UnityUI savelist Menu doesn't work anylonger? A year ago I coded a system to get preview info from save slots, but after I updated to 1.82.5 and saves get disorered (or can get ordered by recent), I cannot straight just preview the info from slots as they don't match save ID
What's your code, and SavesList element properties?
My old code was just using GetSlotIndex(intslot), on a hover script on Load Buttons and send that to get with that SaveFile saveFile = savesList.GetSaveFile(save slot);
Because back then the UI slot 7 was always the Save 7.... same as the Autosave was always the 0. But now I have to actually see what savefile is really is in the "virtual slot" on the UnityUI engine and........I've tried everything for 8 hours. Some of my tries:
(I was there also trying to pass it as a Global Variable in order to get directly an int to convert into save ID in an older post you put there, but I'm never able to get the real SaveID of a UnityUI slot.
its always slot 47 = saveid47 (even if the current pic of the load that Will load if I click is saveid 3 (accodring to the Save Manager) For example,
Debug.Log($"[ShowPreviewFromSlot] Slot {slotIndex} → SaveID {saveFile.saveID}, Label: {saveFile.label}, Updated: {saveFile.GetUpdatedTime()}");
And SaveSystem.ExtractSaveFileVariables(saveFile, OnVariablesExtracted); Works correctly; I mean, It worked before, and I only need to give my LoadPreviewGame file a correct Save ID to look at and gives me back all the information... but slots ids and the saves that are actual in aren't the same. Been yesterday 8 hours trying this to work using lots of different codes...
... Or just the saves not getting disordered, a thing that I don't know why it happens. the AC option order by recent works correctly, but then again, with my old method to retrive the save file, it gives me an incorrect saveID just manually checking at the unityUI slot (that convoluted code I share was just my 20th attempt of trying to retrieve via code what saveID was really asigned to the menu internally... I also have other Saving problems (minor, on my end) so I wanted to first to get this system back and running to help me debug.
I'm trying really hard to not update AC any more.
What was the result of the original code above? That is, manually assigning the GameObject involved (loadSlotButton) and using that to retrieve the index via GetSlotIndex and then GetSaveFile?
If you're experiencing an issue with save ordering, share details with screenshots and steps to recreate and I can take a look into it.
With that code, I got the "[SaveSlot] GetSlotIndex returned invalid index"); debug line. (looking at all the debug, Correctly retrieves the UI linked button without me telling me where to get it, so AC knows what button is looking at, but for some (strange reason to me, don't "finds a save inside there" (return invalid index).
Anyway, it was a long shot, I tried already so much stuff.
That code .. Finding the "real slot AC think the slot is" was inspired by this piece of your code ('cause I can easily send the save slot in the custom label saving method por example... So AC has an integrated way to know what slot I'm picking..
So I thought that GetOptionID would be the quickest shot but I was not able to enter by the level of protection. After trying 8 hours between myself and getting advise from chatgpt (that was useful creating the original script that worked)
ALSO, An Important Clue is what I explain in PSS at the end of the post.
There is two things here:
1)If saves would not get disordered, (every time I make a new save, some previous saves change slots in... What I've not find a pattern yet), my old code would work.
2)If saves are order by recent, my old code would not work.
3)If savings getting disordered is an abherrant behaviour you're not aware of, that's worthy of a new thread, But...
Due to:
1) Having the Load Game Preview Info will help me debug better the save system
2) having a way to get the correct saveFile frm the hovered button will make my system works in either Ordering method that exists, or if they're disordered randomly (I hope),
the first step would just be try a code that really works Getting the save file on a hovered UI button, sameway there is public accessible code to get the inventory item on a specific UIbutton.
I'm trying to not update AC anymore 'cause my game is constantly released to the public and we often find bugs after the Beta Release, and if they're AC related, in the end I had to upadate the engine and the rabbit hole starts again, just because my system is so custom and complex.
If I would had to update it for a final time I would do it, I'm just scared of how many more things will break again with an update x'D
So what do you think:
P)Is saves getting randomly ordered after saving (savefiles switching places inside slots) a 'Cause that could lead to AC not knowing what savefile is in the slot?
If that would be a case, I would just order them by recent and go with it, for my the only important part is retrieving that Load Game Preview info.
->
Q)So, in any of the two cases, I need to find a way to retrieve the correct SaveFile from the hovered button.
PS) The saves getting randomized on save started after updating to 1.82.5 to get your fix about Custom Save Labels. While I was trying to fix that myself, I could also mess up with the correct functioning of my custom save labels (Some timing issues that blocked the game on Build but not in Editor while trying to get the Input up, but I changed that)
PSS) Strangely enough, when I load a game (editor play,straight go to load menu, load menu), the gVAR int SaveSlot is updated with the CORRECT saveID of the Loaded game (That's why I think AC send save slot to parameter is my way to use "GetSaveFile" easily). What bogles my mind, is that SaveSlot gvar is only used by the Custom Save Label Actionlists workthread... So it should never be triggered when Loading, and SaveSlot should not be updated. So I understand nothing.
Explanation: I start Unity. Hit Play in the Editor. Go to Load menu. Hit the eight button (slot 8, saveid 8 if I were to use my old GetSaveFile code). But in the save manager, I do know that that save pic corresponds to SaveID38. After I load the game, suddenly gVAR SaveSlot is changed to 38. So .... AC knows perfectly via its interior code what save I'm loading... but that Intenger is Only updated by an actionlist, the ClickOnSave one.
Does your SavesList element scroll? If not, GetOptionID will just return the same value you pass to it.
It's difficult to understand the specifics of your situation, but if you're in need of getting a Save ID value from a given index value, you can use this:
That worked perfectly. Now I'll see what is happening with the order issue. Even in "order savelists by update time" is disordering older saves. I'll take a deep look and if needed open a thread.
Ok, important update about the behaviour... Withour reordering by recent time, If I check any (or both, save and load) lists with "Allow empty slots", the saves don't get shuffle and they coincide with the list from the Save Manager, but the load game preview is wrong (which is strange, make the previous code that works not retrieving well the saveID.
In the AC Manage Saves menu, all saves are ordered by ID (from 1 to 49). (I bet in that case my old code of just getting slot ID = save ID would work... But it doesn't make sense your code that works without that option check don't work well (it shows the preview save info of the menus that would be without the allow empty slots On)
I do know in the past I skipped using avoid empty slots 'because it gave problems, but it was like in 1.7x version. Can't remember what was the problem.
In any case, this gaves a lot of information.
Ok. Some of my problems were related to not knowing in deep the changes needed in some last updates around my version (like saving as index instead of slot). I'll try using Allow Empty slots...