Why isn't this working? I'm trying to put all my object tables in a single table and use a forloop to iterate through each of them and draw. It shows a error message saying: "}" expected near "=" at line 5
function love.load()
solidstatic = {
ground = {x = 0,y = 160,width = 1000,height = 1000}
box = {x = 80,y = 100,width = 15,height = 15}
}
end
function love.draw()
for i,obj in ipairs(solidstatic) do
love.graphics.rectangle("fill",obj[x],obj[y],obj[width],obj[height])
end
end
Simple, you forgot the comma (,) at the end of the line starting with ground =.
Since it found the word "box" instead of a comma, it expected the closing } bracket of the solidstatic table.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
I was messing with this for hours trying to solve it, and I eventually deleted the comma to see if it was the problem. I forgot to add it again, since I kept getting the same error message
function love.load()
solidstatic = {
ground = {x = 0,y = 160,width = 1000,height = 1000},
box = {x = 80,y = 100,width = 15,height = 15}
}
end
function love.draw()
for i,obj in ipairs(solidstatic) do
love.graphics.rectangle("fill",obj[x],obj[y],obj[width],obj[height])
end
end
You should read more able how tables work in Lua. It will save you a lot of time and frustation if you just read and understand some stuff. https://www.lua.org/pil/2.5.html
Tanner wrote:You should read more able how tables work in Lua. It will save you a lot of time and frustation if you just read and understand some stuff. https://www.lua.org/pil/2.5.html