Trouble with Movement of Physics Objects

yes.

It’s really important to understand this. The way I think of it, Codea (actually Lua) can only store numbers or strings in variables, so any time you want to store a vec2, a table, a class, a physics object in a variable, Codea just stores the address where that thing can be found.

When you say

function DoSomething(a)
    --code
end

Codea treats this as

DoSomething = function(a)
    --code
end

ie it stores the code somewhere safe, and puts its memory location in DoSomething

You can see this by printing the following two statements

print(DoSomething) --will print a memory address
print(DoSomething**()**)  --will run the function

The first statement just says “print out what is stored in DoSomething”, which is a memory address

The second statement says “run the function whose address is in DoSomething”, because double brackets mean “run the function”

Then, when writing in actual Lua, should the first example be used to declare a function, or he second one?

It also means that if you write

a=vec2(100,200)
b=a
b.x=333
--changing b also affects a!
print(a) --> (333,200)

because when you set b=a, it is storing the address of a, ie they are both pointing to the same object! So when you change either, the other changes too.

To copy the vector, you need to copy the x and y values separately (exactly as you were doing). Because those are just numbers, those numbers will be copied, not a memory address.