Forum rules - please read before posting.

ExtractSaveFileVariables change

I have an old custom action to extract a specific variable from a save file. This is the relevant bit:

        public override float Run ()
        {

            int saveNumber = AC.GlobalVariables.GetIntegerValue(15);
            SaveFile saveFile = KickStarter.saveSystem.GetSaveFile(saveNumber);
            List<GVar> saveVars = SaveSystem.ExtractSaveFileVariables(saveFile);


            GVar correctVar = null;
                foreach (GVar saveVar in saveVars)
                {
                    if (saveVar.id == 13)
                    {
                        correctVar = saveVar;
                        break;
                    }
                }
                string saveDay = correctVar.GetValue();

                AC.GlobalVariables.SetStringValue(14, saveDay);

                return 0f;

        }

But I'm not sure how to incorporate the new callback parameter to make this work. I took a look at the scripting guide, but it doesn't seem to be updated yet? If you could point me in the right direction, I'd really appreciate it.

Comments

  • edited December 2022

    Yes, it uses a callback now in case the process can't be run instantly:

    private bool gotVariables;
    
    public override void AssignValues()
    {
        gotVariables = false;
    }
    
    public override float Run ()
    {
        if (!isRunning && !gotVariables)
        {
            isRunning = true;
            int saveNumber = AC.GlobalVariables.GetIntegerValue(15);
            SaveFile saveFile = KickStarter.saveSystem.GetSaveFile(saveNumber);
            SaveSystem.ExtractSaveFileVariables(saveFile, Callback);
        }
    
        if (isRunning)
        {
            return defaultPauseTime;
        }
        return 0f;
    }
    
    private void Callback (List<GVar> saveVars)
    {
        GVar correctVar = null;
        foreach (GVar saveVar in saveVars)
        {
            if (saveVar.id == 13)
            {
                correctVar = saveVar;
                break;
            }
        }
        string saveDay = correctVar.GetValue();
    
        AC.GlobalVariables.SetStringValue(14, saveDay);
        isRunning = false;
        gotVariables = true;
    }
    
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.