Issue with trying to loop through a table?

Just trying to loop through a table here, but it doesn’t seem to work. #words returns 0.

local words = {

x = "yes"

, y = "no"

, z = "yes"

}

for i = 1,#words do

print(words[i])

if string.match(words[i], "yes") then

print("got a match")

end

end

Try this :

local words = {

	x = "yes"

	, y = "no"

	, z = "yes"

}

for _,word in pairs(words) do
	print(word)
	if string.match(word, "yes") then
		print("got a match")
	end
	wait(.1)
end
1 Like

About your numeric for… you can’t count a dictionary by using “#” but arrays unless you want the count result a zero value.

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