Posts: 21
Threads: 3
Joined: Sep 2014
Thanks: 2
Given 4 thank(s) in 4 post(s)
Hello, I am wondering if its possible to get Arrays with the cIniFile class?
I Know INI files can have arrays but looking at the docs, there is no functions for arrays.
Is there a different way to get arrays from INI files?
Posts: 302
Threads: 8
Joined: Feb 2014
Thanks: 48
Given 30 thank(s) in 26 post(s)
What do you want to save in the INI Array?
Why not use a SQLLite database?
Posts: 21
Threads: 3
Joined: Sep 2014
Thanks: 2
Given 4 thank(s) in 4 post(s)
Its for a config, I need to save a motd message, and the motd needs to be multiple lines.
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1075 thank(s) in 852 post(s)
You could use several approaches here:
- Store the strings in a single value in an INI file, separated by a separator: "value1|value2|value3", then use StringSplitAndTrim() on the string value you read from the INI file
- Use a config file that is a Lua file. Such a config file must not be stored in the plugin's folder, but then is quite free to use any Lua to provide the configuration; then use Lua's dofile() function to read the config. The only downside is that it's difficult-to-impossible to make changes to such a file programmatically. Gallery plugin uses a Lua config file, you can use that as a reference.
Posts: 21
Threads: 3
Joined: Sep 2014
Thanks: 2
Given 4 thank(s) in 4 post(s)
I was thinking of using a seperator, only problem is that for a motd, the line would be really bad to read.
I was playing around with the lxp but I never figured out a good way to make it parse the XML file to a Table so that didn't work either.
Is there a reason why the cIniFile class doesn't have a function for arrays/tables?
Posts: 952
Threads: 16
Joined: May 2013
Thanks: 66
Given 105 thank(s) in 89 post(s)
The server has never needed to use it, I suppose.
Posts: 21
Threads: 3
Joined: Sep 2014
Thanks: 2
Given 4 thank(s) in 4 post(s)
Is there any plans to add support for it?
Could be useful for message configs and similiar?
Posts: 21
Threads: 3
Joined: Sep 2014
Thanks: 2
Given 4 thank(s) in 4 post(s)
Could work for the project I am working on, but would be nicer to have a real function for it.
In case you have a lot of lines and you have to change multiple lines, you might forget to edit the number, then the for loop will fail.