INI Files
#11
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?
Reply
Thanks given by:
#12
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
Reply
Thanks given by:
#13
(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 
Reply
Thanks given by:
#14
Thanks for the help guysBig Grin
Reply
Thanks given by:
#15
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()
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)