I've got a table with user input data in passed to a function and I want to make a second table which is a copy of the first except for it's two nested tables of sieve and sieveDown's x and y values being transformed by hump.camera to the game camera system. The format of inputData is
Code: Select all
inputData = {
sieve = {},
sieveDown = {}
}
However that's actually what I wanted the game coord table to look like, because the x and y entries there are the transformed versions rather than pixels from top left of the screen where my mouse is that they should be and start off as.
I've tried editing the second line in the above code to being a function to perform a shallow copy, a deep copy, the current version and the current version without the dummy entry and they all cause the same bug which is evident in the print logs.
Code: Select all
function input.setupGameCamera(inputData)
local gameCameraInputData = {sieve = {},dummy=false,sieveDown = {}} --copyTable(inputData) --{sieve = {},sieveDown = {},dummy=false}
local function queryInRange(x, y)
return (x > window.gameArea.x and x < window.gameArea.x+window.gameArea.w and
y > window.gameArea.y and y < window.gameArea.y+window.gameArea.h)
end
-- get each table entry v and replace the x and y coords with the
-- gameCamera versions
for k, v in pairs(inputData.sieve) do
if queryInRange(v.x,v.y) then
--local ox, oy = v.x, v.y
print("0:"..v.x)
local gx, gy = gameCamera:worldCoords(v.x,v.y)
print("1:"..v.x)
gameCameraInputData.sieve[k] = v
print("2:"..v.x)
gameCameraInputData.sieve[k].x, gameCameraInputData.sieve[k].y = gx,gy ---Buggy line
print("3:"..v.x)
v.cam = true
end
end
... ect
Code: Select all
0:798 -- x coord of mouse on screen
1:798 -- x coord of mouse on screen
2:798 -- x coord of mouse on screen
3:393 -- x coord of mouse in game camera!
I thought this should only happen if my second line was gameCameraInputData = inputData but it's still happening?
Full Love file attached (first log on screen is inputData, second is gameCameraInputData)