Table loop not returning first index

So I’m trying to loop through a table within a table that stores some info I need, and I’m trying to check a certain index but it prints nil, but I know that the table values inside arent nil because I loop through and print them and I can see each value, any idea whats going on?

This is what the print(value) prints
image

This is what print(v[1]) prints
image

for i,v in pairs(UncompleteM) do
	print(i,v) -- v is the table inside of uncompleted missions
	for index,value in pairs(v) do
		print(value) -- stuff in inside of the table
	end
	print(v[1]) -- Im trying to print the first index of v which is the table inside of UncompleteM.
end
2 Likes

It looks like you are using a dictionary (Also known as a Hash Map) which the values cannot be indexed with integer values. If you print the index you will see that things other than integers. If you change your loop from pairs to (iterative pairs) ipairs, the dictionary will still appear to be empty

Here a visualization of the difference.

---Table
{
[1] = "Hi";
[2] = "Bye";
[3] = "Goodnight";
}

---Dictionary
{
"Hello" = 56;
"World" = 57;
}

Two things I can think of off of the top of my head - so you know ‘1’ is a value, but are you sure it’s an index? And the second thing I would try is double check the typing on your index, because in some cases it’s possible to have an index of “1” (string) but what you want could be 1 (a number).

It’s kind of hard to tell without seeing your table, but it’s a start!

But how should I go about fixing it?

You’d have to describe more of what you are doing so that I can recommend a more optimal solution.

Never mind I fixed it lol.
30 chars