Forum rules - please read before posting.

new game menu

2»

Comments

  • edited June 2023

    By "Global variables", are you referring to those from AC or Steam?

    What custom scripts are you using to link the two together?

    Options data needs to all come from the same source - by default, this is Unity's PlayerPrefs. This can be changed (see the Manual's "Custom save formats and handling" chapter) but for individual variables, you'd need to have a means of updating a specific variable once a given profile has been loaded.

    The OnSwitchProfile custom event is triggered once the Profile is changed - and once its option-linked variables have been applied. A hook into this event would likely be the best place to overwrite the PlayerPrefs-linked variable values with equivalents from Steam.

  • @ChrisIceBox

    By "Global variables", are you referring to those from AC or Steam?

    By "Global Variables" I meant from AC.

    What custom scripts are you using to link the two together?

    I'm not actually using the Steam Cloud API to sync the files; I'm using Steam Auto-Cloud. Steam Auto-Cloud allows you to identify multiple file extensions from different file paths to keep synced between devices. And so I have C:\Users\[user]\AppData\LocalLow\[company name]\[project name] listed as a file path, and .save and .log listed as file extensions.

    The Steam Cloud API is different from Steam Auto-Cloud because it requires writing code to set up, and I didn't want to have to look into that because I thought I could do it an easier way by just syncing the different files themselves, but if it doesn't work this way, perhaps I might need to look into figuring that out. The description for Steam Cloud API can be found here, and Steam Auto-Cloud is right below it here.

    Honestly, it would be really helpful and nice if we could specify for different variables in AC to be saved in separate save files and in separate locations.

    The OnSwitchProfile custom event is triggered once the Profile is changed - and once its option-linked variables have been applied. A hook into this event would likely be the best place to overwrite the PlayerPrefs-linked variable values with equivalents from Steam.

    So are you saying that when I load the profile menu and switch to the appropriate profile, I should do the different things to update the button through the OnSwitchProfile event instead of just next in the script after I call AC.Options.SwitchProfileID(int profileID);?

  • The OnSwitchProfile custom event is triggered once the Profile is changed - and once its option-linked variables have been applied. A hook into this event would likely be the best place to overwrite the PlayerPrefs-linked variable values with equivalents from Steam.

    I understand what you're saying now. No we don't overwrite any variables with stuff from steam. At least not with Steam Auto-Cloud. It overwrites entire files, not individual lines within files.

  • Thanks for the explanation. Though, I'm not clear on the distinction you're making between your variables. How are they split, in terms of saving-location? Are some variables option-linked in PlayerPrefs, with others option-linked in Steam?

    Options-linked variables are not recorded in the regular save file - but they can be stored in dedicated files (as opposed to PlayerPrefs) via the the OptionsFileHandler_SystemFile handler. You can use this to override default behaviour - or implement a custom one that stores different variables in different places. The Manual's "Custom save formats and handling" chapter goes over this in more detail.

    If you can share more specific details on exactly what you want saving and where, I can see if I can suggest more specific advice.

    So are you saying that when I load the profile menu and switch to the appropriate profile, I should do the different things to update the button through the OnSwitchProfile event instead of just next in the script after I call AC.Options.SwitchProfileID(int profileID);?

    If you're switching profile through script, there wouldn't be any difference. I suggested that thinking you weren't involving a script to switch profile.

  • @ChrisIceBox I want to have multiple variables saved as options-linked, including preferences that affect performance and should be device-specific. However, there are two variables that I need to have access to before the profile is loaded, so that it can set information on the profile button, specifically the person's first name and an integer determining the profile image. I can accomplish this by making the actual profile name be set as the person's first name, and making the profile pic integer be an options-linked variable, but when I try to implement Steam Auto-Cloud and don't have the options-linked variables synced, the game breaks because neither of those are set. From my understanding, all of the options-linked variables have to be saved in the same location. I can choose to sync those options-linked files with Steam Auto-Cloud as well, but I don't want to have all of the options-linked variables synced, since there are lots of them that should be device-specific because it can affect performance.

    There is no such thing as specific option-linked variables in Steam while using Steam Auto-Cloud. Steam Auto-Cloud only syncs files in certain file paths with different file extensions. Assuming all the variables of one type are stored in the same file, including that file in Steam Auto-Sync will sync all of them. There is no way to differentiate between them in Steam Auto-Cloud. Again, this is different from the Steam Cloud API, which I haven't looked into yet. However, from the description it showed in the Steamworks documentation, it seems like it does a similar thing.

    Are you familiar with the Steam Cloud API though? Because if you can actually separate different variables within the same save file, then I will definitely look into htat.

  • edited June 2023

    Sounds like the best way around it would be to bypass the variables completely and use a dedicated class/file to store that data in.

    Here's a sample script that has static functions to get/set specific profile names and pic integers, as well save/load that data to disk:

    using UnityEngine;
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Runtime.Serialization.Formatters.Binary;
    using AC;
    
    public class AvatarDataHandler : MonoBehaviour
    {
    
        private static AllAvatarData allAvatarData = new AllAvatarData ();
        private const string fileName = "/AvatarData.sav";
    
        public static int GetPicInteger (int profileID)
        {
            return allAvatarData.GetPicInteger (profileID);
        }
    
        public static void SetPicInteger (int profileID, int picInteger)
        {
            allAvatarData.SetPicInteger (profileID, picInteger);
        }
    
        public static string GetName (int profileID)
        {
            return allAvatarData.GetName (profileID);
        }
    
        public static void SetName (int profileID, string name)
        {
            allAvatarData.SetName (profileID, name);
        }
    
        public static void Set (int profileID, string name, int picInteger)
        {
            allAvatarData.Set (profileID, name, picInteger);
        }
    
        public static void Save ()
        {
            BinaryFormatter bf = new BinaryFormatter();
            FileStream stream = new FileStream (Application.persistentDataPath + fileName, FileMode.Create);
    
            string dataAsJson = JsonUtility.ToJson (allAvatarData);
            bf.Serialize (stream, dataAsJson);
            stream.Close();
        }
    
        public static void Load ()
        {
            if (File.Exists(Application.persistentDataPath + fileName))
            {
                BinaryFormatter bf = new BinaryFormatter();
                FileStream stream = new FileStream(Application.persistentDataPath + fileName, FileMode.Open);
    
                string dataAsJson = bf.Deserialize(stream) as string;
                JsonUtility.FromJsonOverwrite (dataAsJson, allAvatarData);
    
                stream.Close();
            }
        }
    
    
        [Serializable]
        private class AllAvatarData
        {
    
            public List<AvatarData> avatarDatas = new List<AvatarData> ();
    
            public int GetPicInteger (int profileID)
            {
                foreach (AvatarData avatarData in avatarDatas)
                {
                    if (avatarData.profileID == profileID) return avatarData.picInteger;
                }
                return 0;
            }
    
            public void SetPicInteger (int profileID, int picInteger)
            {
                foreach (AvatarData avatarData in avatarDatas)
                {
                    if (avatarData.profileID == profileID)
                    {   
                        avatarData.picInteger = picInteger;
                        return;
                    }
                }
                avatarDatas.Add (new AvatarData (profileID, GetDefaultName (profileID), picInteger));
            }
    
            public string GetName (int profileID)
            {
                foreach (AvatarData avatarData in avatarDatas)
                {
                    if (avatarData.profileID == profileID) return avatarData.name;
                }
                return GetDefaultName (profileID);
            }
    
            public void SetName (int profileID, string name)
            {
                foreach (AvatarData avatarData in avatarDatas)
                {
                    if (avatarData.profileID == profileID)
                    {
                        avatarData.name = name;
                        return;
                    }
                }
                avatarDatas.Add (new AvatarData (profileID, name, GetDefaultPicInteger ()));
            }
    
            public void Set (int profileID, string name, int picInteger)
            {
                foreach (AvatarData avatarData in avatarDatas)
                {
                    if (avatarData.profileID == profileID)
                    {
                        avatarData.name = name;
                        avatarData.picInteger = picInteger;
                        return;
                    }
                }
                avatarDatas.Add (new AvatarData (profileID, name, picInteger));
            }
    
            private string GetDefaultName (int profileID)
            {
                return "Profile " + profileID.ToString ();
            }
    
            private int GetDefaultPicInteger ()
            {
                return 0;
            }
    
        }
    
        [Serializable]
        private class AvatarData
        {
    
            public int profileID;
            public string name;
            public int picInteger;
    
            public AvatarData (int _profileID, string _name, int _picInteger)
            {
                profileID = _profileID;
                name = _name;
                picInteger = _picInteger;
            }
    
        }
    
    }
    
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.