Cuberite Forum

Full Version: INI Files
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
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?
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
(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 
Thanks for the help guysBig Grin
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()
Pages: 1 2