Are you able to find a table in a table using this method?

Simple question, just a yes or a no. Wondering if you could do this to find a table, since it isn’t working for me.

print(table.find(Replies, "Reply"..ReplyNumber))

So for example, this is my “Replies” table

local Replies = {
	["Initial"] = {
		"ReplyDialogue1",
		"ReplyDialogue2",
		"ReplyDialogue3",
		"ReplyDialogue4",
		"ReplyDialogue5",
		
	},

	["Reply5"] = {
		"ReplyDialogue1"

	},

	["Reply6"] = {
		"ReplyDialogue1"
	},
}

I have everything else set up, but I want it to detect it so if you’ve clicked on the in this case, the 5th or 6th reply, then it would do something else.

			if not table.find(Replies, "Reply"..tostring(ReplyNumber)) then -- needs to fix
				-- firing the server with no replies here
				
			else
				-- firing the server with replies here
				
			end
-- Creating a table within a table
myTable = {
    innerTable = {
        key1 = "value1",
        key2 = "value2"
    },
    anotherKey = "anotherValue"
}

for key, value in pairs(myTable) do
    if type(value) == "table" then
        for innerKey, innerValue in pairs(value) do
            print(innerKey, innerValue)
        end
    else
        print(key, value)
    end
end

Nevermind, I got it by just ditching the table.find, replacing it with if not Replies["Reply"..ReplyNumber] then

table.find(mytable, valuetolookfor) searches for a value. And as you found out, to determine if a key exists in the table, you just have to do mytable[key] which returns the value of the key or nil if there is no value at that key. Just a bit of info on the reason that table.find failed to work as you wanted it to.

1 Like

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