View Single Post
  #1  
Old 04-14-2008, 09:52 PM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
loadIni2() - loadIni() replica

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.

PHP Code:
function loadini2(file)
{
  
temp.data.loadlines(file);
  
temp.var = new TStaticVar();
  
  for (
temp.linetemp.data) {
    if (
temp.line.starts("[")) {
      
this.preffix temp.line.substring(1temp.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() + 1temp.line.length());
  }
  
  return 
temp.var;

Use it with:
PHP Code:
this.var = loadIni2(path/to/file/filename.ext); 
Example of .ini file:
PHP Code:
[slotA]
charname=Rawr
level
=17

[slotB]
charname=Roar
level
=
this.var.slotA.charname would echo "Rawr".
__________________
Follow my work on social media post-Graal:Updated august 2025.

Last edited by xXziroXx; 04-14-2008 at 10:11 PM..
Reply With Quote