Attempt to perform arithmetic on local 'upgradeCapEfi' (a table value)

I am trying the concept of relational positioning (creating objects based on the location of other objects) and I am having a bit of a problem. I have a text objects inside of circle, and when I try to set its x and y value:

local upgradeCapEfi = display.newCircle(left + 20, bottom, 50) upgradeCapEfi.fill = \_PURPLE\_ local upgradeText = display.newText("Upgrade: \nLevel " .. moneyLVL, 0, 0, 100, 0, native.systemFont, 10) upgradeText.x, upgradeText.y = upgradeCapEfi.x + 20, upgradeCapEfi - 20

I get an error saying  “Attempt to perform arithmetic on local ‘upgradeCapEfi’ (a table value)” Why is the circle’s coordinates a table value?

upgradeCapEfi.y

not

upgradeCapEfi

upgradeText.x, upgradeText.y = upgradeCapEfi.x + 20, upgradeCapEfi.y - 20

If you’re new, you should avoid doing this:

upgradeText.x, upgradeText.y = upgradeCapEfi.x + 20, upgradeCapEfi.y - 20

 and do this instead:

upgradeText.x = upgradeCapEfi.x + 20 upgradeText.y = upgradeCapEfi.y - 20

It will make debugging much easier since the bug has the line number in it and with only one statement to debug it will be clear.

Oops, careless mistake.

Thanks for pointing this out!

I want to echo @roaminggamer’s advice. Even if you’re an experienced developer, there is value to writing clear code. While Lua allows you to assign multiple variables in one assignment statement and it saves a few lines of code, it makes the code harder to follow and you can easily miss a misspelled variable name that with Ed’s suggestion would stand out and be easily spotted.

Rob

Thanks, I will keep this in mind.

upgradeCapEfi.y

not

upgradeCapEfi

upgradeText.x, upgradeText.y = upgradeCapEfi.x + 20, upgradeCapEfi.y - 20

If you’re new, you should avoid doing this:

upgradeText.x, upgradeText.y = upgradeCapEfi.x + 20, upgradeCapEfi.y - 20

 and do this instead:

upgradeText.x = upgradeCapEfi.x + 20 upgradeText.y = upgradeCapEfi.y - 20

It will make debugging much easier since the bug has the line number in it and with only one statement to debug it will be clear.

Oops, careless mistake.

Thanks for pointing this out!

I want to echo @roaminggamer’s advice. Even if you’re an experienced developer, there is value to writing clear code. While Lua allows you to assign multiple variables in one assignment statement and it saves a few lines of code, it makes the code harder to follow and you can easily miss a misspelled variable name that with Ed’s suggestion would stand out and be easily spotted.

Rob

Thanks, I will keep this in mind.