Accessing a table within another table

Yo FP, I need to access a table from within another table, this is what I got so far- (this is a gm I’ve been messing around with, it’s teaching me some of good stuff)
(I’m trying to access the strings(“bg_foldsight” and “md_microt1”) within the motherTable. I’ve been at this for like 30 mins :confused:


 local motherTable = {}	
motherTable["cw_ar15"] = {"bg_foldsight","md_microt1"}

function fetch_attachments_for_gun( ply, gun )
	-- local fetch_table = string.Trim( gun, "cw_" )
	
	for i=1, #motherTable do
		print(motherTable*)
	end
end 

Thanks in advance!



local tbl = motherTable["cw_ar15"]
for i=1, #tbl do
	print(tbl*)
end


Like this?

motherTable[“cw_ar15”] will return you the table {“bg_foldsight”,“md_microt1”}

Doing motherTable[“cw_ar15”][ 1 ] Will return you the first string inside that table, e.g. “bg_foldsight”.

If you want to loop through a key - value table, use for key, value in pairs( motherTable ) do end loop.

Your loop is for numeric keys only.

Right, thanks guys. What really had me stuck was the table[“string”][ value ] thing.