Cuberite Forum
INI Files - Printable Version

+- Cuberite Forum (https://forum.cuberite.org)
+-- Forum: Plugins (https://forum.cuberite.org/forum-1.html)
+--- Forum: Plugin Discussion (https://forum.cuberite.org/forum-8.html)
+--- Thread: INI Files (/thread-23.html)

Pages: 1 2


RE: INI Files - Tim - 03-07-2011

Sorry im bumping an old thread but thought it would be silly to make a new one Smile

Is there a way to cycle through all the keys in an ini file and output the key name and the values within it?


RE: INI Files - FakeTruth - 03-07-2011

Yes there is Smile

GetValue not only accepts strings, but also ID numbers; you can use GetValue(0, 0) to get the first value of the first Key

Use GetNumKeys() and GetNumValues( KeyID ) to get the respective number of keys and values in those keys and cycle through all keys/values


RE: INI Files - Tybor - 03-07-2011

(03-07-2011, 12:04 AM)Tim Wrote: Sorry im bumping an old thread but thought it would be silly to make a new one Smile

Is there a way to cycle through all the keys in an ini file and output the key name and the values within it?

Sample code:
PHP Code:
for keyID 0,IniFile:GetNumKeys()-do
  for 
valID 0,IniFile:GetNumValues(keyID)-do
    
Log("keyID = " .. keyID .. ", valID = " .. valID .. ", " .. IniFile:GetValue(keyIDvalID))
    
Log("keyName = " .. IniFile:GetKeyName(keyID))
    
Log("valName = " .. IniFile:GetValueName(keyIDvalID))
  
end
end 



RE: INI Files - Tim - 03-07-2011

Thanks for the help guysBig Grin


RE: INI Files - Tim - 03-07-2011

Got a little confused with the for stuff but if anyone else needs this code and is easily confused by a three letter word, i used the same concept with repeat Smile
Code:
local count = 1
                repeat
                        Server:SendMessage("")
                        Server:SendMessage("# keyname: " .. iniFile:GetKeyName(count), Player)
                        Server:SendMessage("* value2: " .. iniFile:GetValue(iteminiFile:GetKeyName(count), "value1"), Player)
                        Server:SendMessage("* value2: "..iniFile:GetValue(iteminiFile:GetKeyName(count), "value2"), Player)
                        count = count + 1
                until count == iteminiFile:GetNumKeys()