Iterator next not working

Im trying to loop through this module I have and it keeps giving me this error
image

for i,v in next(DialogModule.Lines[v.Name]) do
   print(i,v)
end

The Module

local Dialog = {
	
	["Lines"] = {
			
			["Olivia"] = {
			
					["Hey what's up sis?"] = {
				
						"Nothing much."
					
					},
				
					["Where is the school at?"] = {
					
						"Stop playing around peter and get to school."
				
				
					}
		
			
			
			},
			
			
			
	};
		
	
}

return Dialog

call next with next, t; call pairs with pairs(t)

1 Like

A generic for loop’s syntax is:

-- controlVariable is optional, hence the square parantheses surrounding it
for ... = iterator_function, Table, [controlVariable] do

end

So you should be doing:

for i, v in next, DialogModule.Lines[v.Name] do
    print(i, v)
end

pairs() under the hood is:

function pairs(tbl)
    return next, tbl
end
1 Like

Finally thank you it works and happy birthday

1 Like

Guys, I need help with getting the next key in dictionary with key. Can someone please help me? Next() doesn’t work. How to get next index from dictionary - #11 by John_15051