This is something that's really been nagging at me for some time:
for i = 1, 4 do
x = love.physics.newFixture(diffTable[i].body, diffTable[i].shape):setCategory(10)
x = x:setUserData('Border') -- error here
table.insert(data, x)
end
Let's say I want to insert a variable into the table (basically creating the variable, and then modifying it) and then inserting it:
When I do the x = x:setUserData(...) an error comes up.. saying attempt to index global variable x (nil)
So my question is, how would I create a variable inside a for loop, specifically
I need to do it this way because I'm using love.physics, and creating a fixture with a category. I also need to setUserData at that time but it's not possible.
And I'm sure there has to be a way of doing this... Thanks in advance!!
data.xto be the same value asx? Or do you wantdata[1] = { x = x, y = y }(that's what your first line withtable.insertwould do)?table.insert.table.insertwill put the value at the next numeric index available. lua.org/manual/5.3/manual.html#pdf-table.insert lua.org/pil/19.2.html