Trying to get items position in table with string keys.
3 replies, posted
So i'm working on my credit shop again and I am having issues with the way i'm storing items. When I add items to the global item table i'm using strings as a uid.
To display the items in the shop UI I am looping through the table to make each entry for the items in the shop but I don't know how to get the item's position in the table since the keys are strings and not numbers. I would change to number keys but i'm planning on adding a trading system and website to manage items on.
SCS:addSwep("crowbar",{
name = "Crowbar",
description = "This gives you a crowbar",
cost = "250",
swep = "weapon_crowbar",
model = "w_model.mdl",
perm = false
})
This is how the UI looks:
https://i.imgur.com/ElFGvg0.png
If the keys aren't numeric, then the table is not really sequential. The best you could do for ordering it is by alphabetical. You could get significantly more complex and order it by one of the properties in the table, but that's a big leap forward.
Its a bit messy but this is where my issue is I was using number numeric keys on an earlier revision but I changed to string keys due to the way i'm going to implement the inventory. I was using the keys to position each "item box" but now that they are strings i'm not sure how to go about it.
[Lua] help.lua
Just store a variable and increment it each iteration.
Sorry, you need to Log In to post a reply to this thread.