• Get key value key?
    9 replies, posted
Hello, I'm using util.KeyValuesToTable() on the ulib's ban file (contents:) [code] *first keyvalue* "STEAM_0:1:39734734" { "unban" "1410653157" "time" "1405209957" "reason" "Foul language" "admin" "VX | cheese(STEAM_0:1:39734735)" } "STEAM_0:1:39734736" { "reason" "Spammer" "admin" "VX | cheese()" "unban" "1531353969" "time" "1405209969" "name" "VX | cheese" } [/code] And i'm trying to get the key (for example, the key of the first keyvalue is STEAM_0:1:39734734). How do I get this? When I print the keys of the table I decrypt it in, I get this: [code] unban time reason admin [/code] and when I print the values, I get this: [code] 1410653184 1405209984 Foul language VX | cheese(STEAM_0:1:39734735) [/code] Thanks.
-snip-
[url]http://wiki.garrysmod.com/page/Category:debug[/url] Mess around with that, I managed to do this one time while messing around with that. Also, couldn't you just add the id as a key to the table?
[QUOTE=AnonTakesOver;45372566][url]http://wiki.garrysmod.com/page/Category:debug[/url] Mess around with that, I managed to do this one time while messing around with that. Also, couldn't you just add the id as a key to the table?[/QUOTE] I could, however that's not how ULib naturally does it.
[code] table.KeyFromValue(value) [/code] Not sure if this works with tables. If not, try: [code] local key; for k,v in pairs(KeyValuesToTable thing) do if (k == "steamid") then key = k; break; end end [/code]
[QUOTE=G4MB!T;45372670][code] table.KeyFromValue(value) [/code] Not sure if this works with tables. If not, try: [code] local key; for k,v in pairs(KeyValuesToTable thing) do if (k == "steamid") then key = k; break; end end [/code][/QUOTE] Not working, I can't get the keyvalue's key at all with KeyValuesToTable.
It appears that does not return the key and ignores subsequent key-value tables. Ill ticket it.
[code] local tbl = util.KeyValuesToTable("{"..file.Read("shit.txt", "DATA").."}") PrintTable(tbl); [/code] Output: [code] KeyValues Error: LoadFromBuffer: missing { in file In KeyValues Error: LoadFromBuffer: missing { in file In KeyValues Error: LoadFromBuffer: missing { in file In KeyValues Error: LoadFromBuffer: missing { in file In KeyValues Error: LoadFromBuffer: missing { in file In KeyValues Error: LoadFromBuffer: missing { in file In KeyValues Error: LoadFromBuffer: missing { in file In (*STEAM_0:1:39734736*), [/code]
I opened a ticket for this issue, but since the file itself is not technically in KeyValue format, there is actually nothing wrong with it. However, _Kilburn replied with a fix for the situation: [code] local tbl = util.KeyValuesToTable("\"data\"{"..file.Read("shit.txt", "DATA").."}") /* tbl looks like this: steam_0:1:39734736: reason = Spammer admin = VX | cheese() unban = 1531353984 time = 1405209984 name = VX | cheese steam_0:1:39734734: unban = 1410653184 time = 1405209984 reason = Foul language admin = VX | cheese(STEAM_0:1:39734735) */ [/code] Link to the ticket is here: [url]https://github.com/Facepunch/garrysmod-issues/issues/1323[/url]
Sorry, you need to Log In to post a reply to this thread.