I’ve been trying to wrap my head around Generic For loops and I decided to make this code based on my current understanding:
function setup()
n = {}
numberxplacement = {}
table.addValue(n,2)
table.addValue(n,5)
end
for i, v in pairs(n) do
numberxplacement[v]=n.v*i
end
print(numberxplacement[5])
print(numberxplacement[2])
This code is supposed to multiply the number in the n table by its placement. So since 2 was put into the n table first, the equation should be: 2x1 and since the 5 was put into the table second, the equation should be 5x2. This code, however, will not run for what is most likely the simplest syntax error. Please tell me what that syntax error is so that I may finally be able to understand how generic for loops work. Side Note: does the i (in “for i,v”) AKA the “key” always represent the value’s placement number in the table or could it mean something else?