Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why is ipairs in not working on an array?

Doesn't print anything.

Script

for i,stat in ipairs(sinfo) do
	print(stat)
end

Array

{
	[1]={
		["Name"] = "None",
		["Gradient"] = ColorSequence.new({ColorSequenceKeypoint.new(0,Color3.new(0, 1, 0)),ColorSequenceKeypoint.new(1,Color3.new(0.607843, 0, 0))})
	},
	[2]={
		["Name"] = "Money",
		["Gradient"] = ColorSequence.new({ColorSequenceKeypoint.new(0,Color3.new(0, 1, 0)),ColorSequenceKeypoint.new(1,Color3.new(0, 0.607843, 0))}),
		["Multi"] = {
			"None"
		},
		["Icon"] = "8150337440"
	},
	[3]={
		["Name"] = "Multiplier",
		["Gradient"] = ColorSequence.new({ColorSequenceKeypoint.new(0,Color3.new(1, 0, 0)),ColorSequenceKeypoint.new(.5,Color3.new(0.588235, 0, 0)),ColorSequenceKeypoint.new(1,Color3.new(1, 0, 0))}),
		["Multi"] = {
			["Money"]=2.5
		},
		["Icon"] = "8150337440"
	},
	[4]={
		["Name"] = "Rebirth",
		["Gradient"] = ColorSequence.new({ColorSequenceKeypoint.new(0,Color3.new(1, 0, 0)),ColorSequenceKeypoint.new(.5,Color3.new(0.588235, 0, 0)),ColorSequenceKeypoint.new(1,Color3.new(1, 0, 0))}),
		["Multi"] = {
			"None"
		},
		["Icon"] = "8150337440"
	},
}

1 comment

0

Because you have a 2D table, you need to use nested loops.

1 answer

So what you are doing would only print the table of each dictionary. If you want it to print all the values of the tables within the tables then you would have to do this:

for table1, statTable in ipairs(sinfo) do
	for i, stat in pairs(statTable) do
		print(table1, i, stat)
	end
end

You should get something along the lines of:

1, Name, None
1, Gradient, ColorSequence.new({ColorSequenceKeypoint.new(0,Color3.new(0, 1, 0)),ColorSequenceKeypoint.new(1,Color3.new(0.607843, 0, 0))})

etc...

This discussion is preserved as it was. New answers, comments, and votes are closed.