AMP
                                
                                 AMP copied to clipboard
                                
                                    AMP copied to clipboard
                            
                            
                            
                        JPath for Generic Template not writing to json file.
Bug Report
System Information
- Operating System: Windows 11 Home - 10.0.22623 Build 22623
- AMP version and build date: 2.4.6.4 - 07/09/2023 18:02
- Build Spec: Mainline
I confirm:
- [x] that I have searched for an existing bug report for this issue.
- [x] that I am using the latest available version of AMP.
- [x] that my operating system is up-to-date.
Symptoms
- What are you trying to do? Allow AMP to set config for generic template within json file.
- What are you expecting to happen? AMP to set config setting using JPath lookup.
- What is actually happening? ('Nothing' is not an acceptable answer!) AMP is throwing error message, and config file is not changing.
Reproduction
Add the following lines to the appropriate part of the openRCT2 template At Greelan/AMPTemplates:openRCT2
This is the neccessary addition to metaconfig.json
    ,{
        "ConfigFile":"user-data/users.json",
        "AutoMap":true,
        "ConfigType":"json"
    }
This is the user-data/users.json file, which is the file that the settings should be set to.
[
    {
        "groupId": 0,
        "hash": "",
        "name": "Server"
    },
    {
        "groupId": 0,
        "hash": "",
        "name": ""
    }
]
Additional lines to config.json, settings show up, but settings are not being writen to file, JPath may be incorrect / not functioning properly.
    ,{
        "DisplayName":"User Name",
        "Category":"OpenRCT2 Beta Features",
        "Description":"User Name for first admin, this should be set inorder to mannage games. Your user name based off of name set ingame.",
        "FieldName":"UserName",
        "InputType":"text",
        "ParamFieldName":"$.[1].name",
        "Placeholder":"Admin Player",
        "EnumValues":{}
    }
    ,{
        "DisplayName":"User Hash",
        "Category":"OpenRCT2 Beta Features",
        "Description":"User Name for first admin, this should be set inorder to mannage games. Your user name based off of name set ingame.",
        "FieldName":"UserHash",
        "InputType":"text",
        "ParamFieldName":"$.[1].hash",
        "Placeholder":"159FFE6F65C528C581E7CE710DC02E15AA1E44B1",
        "EnumValues":{}
    }
Error Message from console log when settings are being change.
[23:43:24] [API:admin Activity]   : Changing setting Meta.GenericModule.UserHash to 682c924e2e22b3f5d3a5e7b89d3f3dd6182dcfae
[23:43:25] [Generic:admin Info]   : Merging config file ./openrct2/server/user-data/config.ini (INI format) using Unicode (UTF-8) encoding.
[23:43:25] [Generic:admin Info]   : Merging config file ./openrct2/server/user-data/config.ini (INI format) using Unicode (UTF-8) encoding.
[23:43:25] [Core:admin Warning]   : Returned exception from API call Core/SetConfig
[23:43:25] [Core:admin Error]     : JsonReaderException
[23:43:25] [Core:admin Error]     : [0] (JsonReaderException) : Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray. Path '', line 1, position 1.
[23:43:25] [Core:admin Error]     :    at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader, JsonLoadSettings settings)
   at Newtonsoft.Json.Linq.JObject.Parse(String json, JsonLoadSettings settings)
   at GenericModule.ModuleMain.MergeJSON(String finalPath, MetaConfigFile fileInfo)
   at GenericModule.ModuleMain.WriteMetaconfigs()
   at GenericModule.ModuleMain.SaveChanges(String key, String value)
   at GSMyAdmin.WebServer.WebMethods.UpdateSetting(String node, String value, SettingCacheEntry entry, SettingSpec cache)
   at GSMyAdmin.WebServer.WebMethods.SetConfig(String node, String value)
   at GSMyAdmin.WebServer.WebAttributes.<InvokeMethod>()
   at GSMyAdmin.WebServer.APIService.<InvokeAPI>()
You don't need the . after the $ - so it should be $[1].name
[15:51:32] [API:admin Activity]   : Changing setting Meta.GenericModule.UserName to Jonathan1
[15:51:33] [Generic:admin Info]   : Merging config file ./openrct2/server/user-data/config.ini (INI format) using Unicode (UTF-8) encoding.
[15:51:33] [Core:admin Warning]   : Returned exception from API call Core/SetConfig
[15:51:33] [Core:admin Error]     : ArgumentNullException
[15:51:33] [Core:admin Error]     : [0] (ArgumentNullException) : Value cannot be null.
Parameter name: input
[15:51:33] [Core:admin Error]     :    at Text.RegularExpressions.Regex.Replace(String input, MatchEvaluator evaluator)
   at GenericModule.GenericModuleConfig.ApplicationConfig.SubstituteTemplates(String input, Dictionary`2 variables)
   at GenericModule.ModuleMain.MergeINI(String finalPath, MetaConfigFile fileInfo)
   at GenericModule.ModuleMain.WriteMetaconfigs()
   at GenericModule.ModuleMain.SaveChanges(String key, String value)
   at GSMyAdmin.WebServer.WebMethods.UpdateSetting(String node, String value, SettingCacheEntry entry, SettingSpec cache)
   at GSMyAdmin.WebServer.WebMethods.SetConfig(String node, String value)
   at GSMyAdmin.WebServer.WebAttributes.<InvokeMethod>()
   at GSMyAdmin.WebServer.APIService.<InvokeAPI>()
~~Same log error~~ I got a different error this time.
Are you still working on this? If so I'll reopen. But the error you're getting seems to be because you are adjusting the existing generic template and broke the settings file connection.