PDA

View Full Version : loadIni2() - loadIni() replica


xXziroXx
04-14-2008, 10:52 PM
Since I couldn't get loadIni() to work, and I don't want to halt my script until I find out why, I decided to script my own version of it. Should work the exact same way loadIni() is intended too.


function loadini2(file)
{
temp.data.loadlines(file);
temp.var = new TStaticVar();

for (temp.line: temp.data) {
if (temp.line.starts("[")) {
this.preffix = temp.line.substring(1, temp.line.length() - 2);
continue;
} else if (temp.line.tokenize("=").size() < 2) continue;

temp.str = temp.line.tokenize("=")[0];
temp.var.(@this.preffix).(@temp.str) = temp.line.substring(temp.str.length() + 1, temp.line.length());
}

return temp.var;
}


Use it with:
this.var = loadIni2(path/to/file/filename.ext);

Example of .ini file:

[slotA]
charname=Rawr
level=17

[slotB]
charname=Roar
level=3


this.var.slotA.charname would echo "Rawr".

Chompy
04-14-2008, 11:10 PM
Inverness made one though, back in August 07.
His supports loading and saving of ini files, http://forums.graalonline.com/forums/showthread.php?t=76374

xXziroXx
04-14-2008, 11:13 PM
Oh, I wasn't aware of it, just figured I'd post what I made - no pun intended Inverness.

cbk1994
04-14-2008, 11:39 PM
Inverness made one though, back in August 07.
His supports loading and saving of ini files, http://forums.graalonline.com/forums/showthread.php?t=76374

I thought someone made one when I read his other thread.

TiNI file or something ...

Chompy
04-15-2008, 12:05 AM
I thought someone made one when I read his other thread.

TiNI file or something ...

TIniFile? Inverness made that..