C# config files

I would like to know if it is possible to read XML files as a source for config, I would like to be able to read an XML file then pull data from it and use it in scripts. If this is possible how would I go about implementing this in c#. Reading and pulling data im fine with, but I don’t know how to load an XML as a resource.

Also if XML is not possible/easy what would be another way to go about using a config file like an ini for easy config changes, I dont like using LUA scripts for example for configs.

Load the file with LOAD_RESOURCE_FILE.
Parse it with whatever XML parser you like.

Ive tried that several times with different filetypes but I get errors everytime, I do the following:

string data = Function.Call<string>(Hash.LOAD_RESOURCE_FILE, "name", "config.ini");

I also of course added the file to the resource script as well like so:

files{
'config.ini'
}

Any Ideas what im doing wrong here?

This is the error log btw:

You entered “name” as your resource name, is that the correct name?

Sorry I wrote It from scratch on the forum post the actual code is:

String data = Function.Call<String>(Hash.LOAD_RESOURCE_FILE, "config", "config.ini")

But I still dont really know what it is asking for as a resource name? what should be supplied here?

The resource name is the name of the resource where this config.ini is located. So if your resource is called config, then …/resources/config/config.ini should be the file you’re trying to load.

1 Like

Right so i am now doing:

 String data = Function.Call<string>(Hash.LOAD_RESOURCE_FILE, "/resources/lspdfrm/config/config.ini", "config.ini");

However I get the exact same error,
To fully disclose, I have a resource named lspdfrm within that folder there are my scripts, there is also another folder called config which contains a config.ini which is what I am trying to load.

Then that should be:

 String data = Function.Call<string>(Hash.LOAD_RESOURCE_FILE, "lspdfrm", "config/config.ini");

And that config/config.ini added to the files in your __resource.lua of course.

2 Likes

Mega Thank You!
I thought the resource name was referring to the folder location of the actual resource (i.e. the ini), not the resource itself. All working good now.

1 Like