• util.Table to/from KeyValues
    2 replies, posted
I am working on making a lua that will block sounds by their name and such but the problem I'm running into is saving the table of blocked sounds. [lua] function loadSoundFile() soundFileTbl = util.KeyValuesToTable( file.Read("aaronsound.txt") ) PrintTable(soundFileTbl) --table.insert(soundBlockList, soundFileTbl.block) << Dont Do That Aaron -_- table.Add(soundBlockList, soundFileTbl.block) end function saveSoundFile() local soundFileTbl = {} soundFileTbl["block"] = {} for k, v in pairs(soundBlockList) do soundFileTbl["block"][k] = v end soundFileTbl["radar"] = {} for x, y in pairs(soundShowList) do soundFileTbl["radar"][x] = y end file.Write("aaronsound.txt",util.TableToKeyValues( soundFileTbl )) print(util.TableToKeyValues( soundFileTbl )) end [/lua] the saveSoundFile() works it saves the table as [code] "Out" { "block" { "1" "weapons\357\357_fire2.wav" "2" "^weapons\explode3.wav" "3" "^weapons\explode5.wav" "4" "physics\surfaces\sand_impact_bullet4.wav" "5" "weapons\ar2\fire1.wav" } } [/code] but when I read the file then save it again a extra table get put in and it turns into [code] "Out" { "block" { "1" { "1" "weapons\357\357_fire2.wav" "3" "^weapons\explode5.wav" "2" "^weapons\explode3.wav" "5" "weapons\ar2\fire1.wav" "4" "physics\surfaces\sand_impact_bullet4.wav" "6" "ambient\energy\weld2.wav" } "2" "weapons\ar2\fire1.wav" "3" "physics\concrete\concrete_impact_bullet3.wav" } } [/code] Anyone know why? Also I don't want to use glon or json i want the txt to be humanly readable.
Line 4 in your code - you're inserting not the contents of 'block' but the table itself. Just remove 'table.insert' and set your table normally.
[QUOTE=Nevec;16492146]Line 4 in your code - you're inserting not the contents of 'block' but the table itself. Just remove 'table.insert' and set your table normally.[/QUOTE] What exactly do you mean by normally... -snip- I dont know why but table.Merge works and table.insert dosent :/ -FUUUUU snip- I am completely stupid...... i got table.insert / table.Add or Merge mixed up...... insert sounds more like something that would insert a table into a table and add sounds like adding a line but noooooo :/
Sorry, you need to Log In to post a reply to this thread.