Hello,
This is almost certainly an incredibly basic problem but I’m picking up coding after a long, long absence.
The following is a very simplified version of a problem which keeps cropping up. The first bit of code works as I would expect.
[lua]
local A = 10
local B = A
A = A + 10
print(B)–> Console output: 10
[/lua]
So far, so expected, adding 10 to A has no effect on B.
However, if A and B are tables:
[lua]
local A = {10}
local B = A
A[1] = A[1] + 10
print(B[1]) --> Console output: 20
[/lua]
This, I don’t understand, why does the line A[1] = A[1] + 10 affect B?
In the problems I am trying to solve I often want to “store” a table, and perform actions on a copy of the table while keeping the stored table unchanged, however, in the same way as described above, these actions keep overwriting my stored table.
I’m assuming there is a common way of doing this and if anyone could let me know (a) what it is that I am fundamentally not getting here and ( B) how this sort of thing should be done, I would be very grateful.
Yours,
Jonathon.