#Can you post code for your reading?

1 messages · Page 1 of 1 (latest)

quasi peak
#
{
    ref map<string, string> Police;
    ref map<string, string> EMS;
    ref map<string, string> News;
    
    void SetDefaults(string list)
    {
        switch (list)
        {
            case "Police":
                Police = new map<string, string>();
                Police.Insert("00000000-0000-0000-0000-000000000001", "police ID example");
                break;
            case "EMS":
                EMS = new map<string, string>();
                EMS.Insert("00000000-0000-0000-0000-000000000001", "EMS ID example");
                break;
            case "News":
                News = new map<string, string>();
                News.Insert("00000000-0000-0000-0000-000000000001", "News ID example");
                break;
            default:
                break;
        }
    }
}```
mint talon
#

Ah sorry I can't help with JSONApiStruct as it's bugged and I don't use it at all

quasi peak
#

ahh okay, can I just remove apiStrict and use it like your admin tools one? I had the same issue with that

mint talon
#

can you post the code where you read from the file?

quasi peak
#
 Whitelist_Struct config;
    static string m_configFile = "$profile:RoleWhitelists_Config.json";

    static bool LoadConfig()
    {
        Print("attempting to load "+m_configFile, LogLevel.NORMAL);
        
        SCR_JsonLoadContext configLoad = new SCR_JsonLoadContext();
        
        config = new Whitelist_Struct();
                
        if (!FileIO.FileExists(m_configFile))
        {
            Print(" Whitelist doesn't exist, creating", LogLevel.WARNING);
            config.setAll();
        }
        else
        {
        if (!configLoad.LoadFromFile(m_configFile))
            {
                Print(" Loading Failed", LogLevel.ERROR);
                return false;
            };
            
            if (!configLoad.ReadValue("", m_configFile))
            {
                
                Print("read failed. ", LogLevel.ERROR);
                return false;
            };
        }```
#

this bit is what fails but I don't know why

            {
                Print(configLoad.LoadFromFile(m_configFile));
                Print("RoleWhitelists.LoadConfig | Configuration load failed. Please ensure it exists and is in correct format.", LogLevel.ERROR);
                return false;
            };```
#

i've looked in your admin tools, some random lootconfig and vanilla stuff but can't really work out this json read deal

mint talon
#

You need to make instance of your config because your read value is trying to read the config into the string variable

quasi peak
#

ahh okay, where / how would I do that?

mint talon
# quasi peak ahh okay, where / how would I do that?

something like this

            config = new Whitelist_Struct(); // create an instance
            // read to instance - it was previously loading to null object
            if (!configLoad.ReadValue("", config)) 
            {
                Print("read failed. ", LogLevel.ERROR);
                return false;
            };
        }
quasi peak
#

Ahh so have the config in the readvalue and not the string?

#

I already do config = new Whitelist_Struct();

But then in read value i used the configfile path and not the actual config

#

Or do I do both but call the read on the config instance first?

mint talon
#

Well you was trying to read the config json into your path string which dont make sense

quasi peak
#

Yeah i realise now, so hopefully putting the config instead of the path will work meowfacepalm