Forum rules - please read before posting.

display stats/variables on load buttons

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!

Comments

  • edited May 2023

    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:

    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;
    using AC;
    
    public class DisplaySaveVariable : MonoBehaviour
    {
    
        public GameObject loadSlotButton;
        public string variableName;
        public Text text;
    
        void OnEnable ()
        {
            Menu loadMenu = PlayerMenus.GetMenuWithName ("Load");
            MenuSavesList savesList = PlayerMenus.GetElementWithName ("Load", "SavesList") as MenuSavesList;
            int index = savesList.GetSlotIndex (loadSlotButton);
            SaveFile saveFile = savesList.GetSaveFile (index);
            SaveSystem.ExtractSaveFileVariables (saveFile, OnExtractVariables);
        }
    
        private void OnExtractVariables (List<GVar> variables)
        {
            foreach (GVar variable in variables)
            {
                if (variable.label == variableName)
                {
                    text.text = variable.GetValue ();
                }
            }
        }
    
    }   
    
  • 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.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.