• SortedPairsByMemberValue issue.
    4 replies, posted
for k,v in SortedPairsByMemberValue( LocalPlayer():GetInventory(), "category" ) do 1 = Hamburger Hamburger: category = 5 name = Hamburger quant = 30 [ERROR] lua/includes/extensions/table.lua:537: attempt to index a string value with bad key ('category' is not part of the string library)   1. error - [C]:-1    2. __index - lua/includes/extensions/string.lua:297     3. SortedPairsByMemberValue - lua/includes/extensions/table.lua:537 I'm trying to sort the items in my inventory by using their category. The first line is my code. The second section is my printed inventory using PrintTable. The last part is the error it throws me. I don't understand why it's not working. It literally makes no sense. And yes, LocalPlayer():GetInventory() returns a table, so that is not the problem.
Not sure, but I think the table you pass to it has to be sequential.
Isn't that the point of the function though? To make the table sequential? I'm not exactly sure what you're trying to say.
If you look at the source of the function, there's an enlightening comment. All table entries must be a table! I bet your table has a string value in it. Strings in Lua have a feature where if you index them like a table, you will get a function from the string library. This is to enable code like this: local str = "formatted string with '%s' value" local parts = str:format("myvalue") If a function from the string library isn't found, you get the error message you posted.
I had: Inventory = { ["Hamburger"] = { category quant etc.... } } After a lot of changing around of how the functions worked, I reverted it to remove the ["Hamburger"] as the name of the table and just made it a generic key. This fixed the issue.Thank you for the reply, was super helpful!
Sorry, you need to Log In to post a reply to this thread.