What's wrong with this? I'm reading the API Documentation, but since the error messages aren't pretty describing so I have to ask questions here. <filename unknown>:0 ... filename unknown? What the faaaak?Code:class StoredData { public HashSet<string> itemList = new HashSet<string>(); public StoredData() { } } StoredData storedData; void Loaded() { storedData.itemList.Add("OK"); Interface.Oxide.DataFileSystem.WriteObject("NoComponent", storedData); }
Code is for testing purposes, no productional, fail-safe etc.
[DOUBLEPOST=1479911900][/DOUBLEPOST]PS. Have to create file manually. I will try that. If it's the reason why docs doesn't mention that the file must be created using basic functions of C#. I were wondering that the file will be automatically created by Oxide API.
Solved Writing a config file error
Discussion in 'Rust Development' started by Pastori, Nov 23, 2016.
-
Wulf Community Admin
The code you are using above is the DataFile API (oxide/data), not for the Config API (oxide/config). The will be created once data is stored to it and you trigger the write like you have above. If you want to use the Config API instead, you'd need to use the LoadDefaultConfig() hook for automatic file creation or create it using a similar method to what you have above.
-
Yeah. It didn't work anyways whenever it was a data. I successfully created a configuration with List<string>, because I'm listing some items to it.
-
Wulf Community Admin
If you could post the full error, that'd be more helpful in pointing out why it wasn't working. -
How do I define the itemList content to be a Config["itemList"] content.Code:
List<string> itemList = new List<string>(); void Loaded() { // Define } protected override void LoadDefaultConfig() { PrintWarning("Creating a new configuration file."); Config.Clear(); itemList.Add("gears"); itemList.Add("metalblade"); itemList.Add("metalpipe"); itemList.Add("riflebody"); itemList.Add("roadsigns"); itemList.Add("rope"); itemList.Add("sewingkit"); itemList.Add("smgbody"); itemList.Add("metalspring"); itemList.Add("techparts"); itemList.Add("propanetank"); Config["itemList"] = itemList; SaveConfig(); }
-
Wulf Community Admin
You'd have to store it as a List<object> and cast later. -
I don't know other way to do it than creating a new class.
and adding it to list as object.Code:class PluginItem { public string shortname { get; set; } public PluginItem() { shortname = shortname; } }
[DOUBLEPOST=1479917559][/DOUBLEPOST]I seriously have a clue how the hell I'm supposed to load all of the items from the JSON object. I can't just remember. I think I'm getting too old for this.Code:List<PluginItem> itemList = new List<PluginItem>(); class PluginItem { public string shortname { get; set; } public PluginItem(string sn) { shortname = sn; } } void Loaded() { foreach(PluginItem item in itemList) { Puts(item.shortname); } } protected override void LoadDefaultConfig() { PrintWarning("Creating a new configuration file."); Config.Clear(); itemList.Add(new PluginItem("gears")); itemList.Add(new PluginItem("metalblade")); /*itemList.Add("gears"); itemList.Add("metalblade"); itemList.Add("metalpipe"); itemList.Add("riflebody"); itemList.Add("roadsigns"); itemList.Add("rope"); itemList.Add("sewingkit"); itemList.Add("smgbody"); itemList.Add("metalspring"); itemList.Add("techparts"); itemList.Add("propanetank");*/ Config["itemList"] = itemList; SaveConfig(); }Last edited by a moderator: Nov 23, 2016 -
Wulf Community Admin
Does this not work:
I do use List<object> in a few of my plugins, but a little differently. Take a look at CountryBlock if you'd like to see.Code:List<object> itemList = new List<object>(); void Loaded() { // Define } protected override void LoadDefaultConfig() { PrintWarning("Creating a new configuration file."); Config.Clear(); itemList.Add("gears"); itemList.Add("metalblade"); itemList.Add("metalpipe"); itemList.Add("riflebody"); itemList.Add("roadsigns"); itemList.Add("rope"); itemList.Add("sewingkit"); itemList.Add("smgbody"); itemList.Add("metalspring"); itemList.Add("techparts"); itemList.Add("propanetank"); Config["itemList"] = itemList; SaveConfig(); }
