Forum rules - please read before posting.

How do I display some specific global variables on each of the save files in the load screen?

How do I display some of their specific global variables on each archive in the load screen? I want the top of each grid to show the screenshot and the bottom to list some global variables for that archive.

Comments

  • The ExtractSaveFileVariables function can be used to return a List of Global variables associated with a given save file. This can then be iterated through to find the intended variables, and either used to update the Save File's display label or a separate Label element.

    What variables are you looking to read, and where would they be displayed? Screenshots or a mockup that explains the intent would be best, if possible.

  • Is this picture clear?

  • edited September 2022

    https://streamable.com/m4a3wk
    The box in the middle has a screen shot at the top, a line of playtime in the middle, a list of values for the main character's attributes at the bottom, and a delete button at the bottom right.

  • A couple of prerequisites:

    1. You'll need to rely on Unity UI for your Menu's display, as this gives more control over customisation
    2. Open up AC's MenuSavesList script and add the following function. I'll make the same addition to the next release:

      public SaveFile GetSaveInSlot (int slot)
      {
      int saveID = GetOptionID (slot);
      return KickStarter.saveSystem.GetSaveFile (saveID);
      }

    Then, open your Unity UI prefab for the menu and create a new Text object to show the variables in. Attach this script to it and fill in the details in its Inspector:

    using UnityEngine;
    using UnityEngine.UI;
    using AC;
    
    public class DisplaySaveVariables : MonoBehaviour
    {
    
        public int saveSlot;
        public Text text;
        public string saveMenuName = "Save";
        public string saveElementName = "SavesList";
        public int[] variableIDs;
    
        void OnEnable () { EventManager.Delegate_OnMenuTurnOn += OnMenuTurnOn; }
        void OnDisable () { EventManager.Delegate_OnMenuTurnOn -= OnMenuTurnOn; }
    
        void OnMenuTurnOn (Menu menu, bool isInstant)
        {
            if (menu.title != saveMenuName)
            {
                return;
            }
    
            MenuSavesList savesList = PlayerMenus.GetElementWithName (saveMenuName, saveElementName) as MenuSavesList;
            SaveFile saveFile = savesList.GetSaveInSlot (saveSlot);
            if (saveFile != null)
            {   
                GVar[] vars = SaveSystem.ExtractSaveFileVariables (saveFile).ToArray ();
                string variableText = GetVariableText (vars);
                Debug.Log (variableText);
                if (text) text.text = variableText;
            }
            else
            {
                if (text) text.text = string.Empty;
            }
        }
    
        string GetVariableText (GVar[] vars)
        {
            string result = "";
            foreach (int variableID in variableIDs)
            {
                foreach (GVar _var in vars)
                {
                    if (_var.id == variableID)
                    {
                        result += _var.label + ": " + _var.GetValue () + "\n";
                        break;
                    }
                }
            }
            return result;
        }
    
    }
    

    This script will populate the Text component with variable data from the save, given the "Save Slot" index variable in the SavesList element.

    If you encounter issues, share screenshots of your UI prefab and Menu/SavesList element's properties. Images can be hosted on imgur.com.

  • Thanks!I will try!

  • Nice!It works!

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.