Would this be possible in any way?

I’m developing an inventory system and I’m trying to access image ID’s through a ModuleScript dictionary. In the code I have, items and their values are passed to the client via parameters in a function: local function FillSlot(Num1,Item1,Num2,Item2,Num3,Item3,Num4,Item4). The Item1,Item2,etc is the names of the objects. I take the item names and get rid of the whitespace if they aren’t nil.

if Item1 then
		local Item1Image = string.gsub(Item1, "%s+","")
	end
	if Item2 then
		local Item2Image = string.gsub(Item2, "%s+","")
	end
	if Item3 then
		local Item3Image = string.gsub(Item3, "%s+","")
	end
	if Item4 then
		local Item4Image = string.gsub(Item4, "%s+","")
	end

Those unwhitespaced names are the same as what they’re called in the dictionary. I want to be able to use those ItemImage variables to access parts of that dictionary. Like a functioning version of this line: v.ItemImage.Image = ItemImages.Item1Image. how would it be achieved? (ItemImages is the module script being referenced.)

1 Like

I didn’t fully understand what your explanation meant, but if the unwhitespaced names are the same, are you asking how to call the value from the table? knowing that your string and the key are the same?

for that you can just do

v.ItemImage.Image = ItemImages[Item1Image]

--[[
ItemImages[key] = value
I'm assuming the value of the string Item1Image is the same as the
key from ItemImages, which is also a string
]]

is this what you’re asking?

2 Likes

I’m stupid for not realizing this was an option. Thank you for helping.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.