Code: Select all
push = require 'push'
WINDOW_WIDTH = 1280
WINDOW_HEIGHT = 720
VIRTUAL_WIDTH = 512
VIRTUAL_HEIGHT = 288
temp1,temp2,temp3={},{},{}
function love.load()
testTable ={{{x=1,y=1},{x=1,y=2},{x=1,y=3},{x=1,y=4}}}
testString = 'BEFORE SWAP'
love.graphics.setDefaultFilter('nearest','nearest')
push:setupScreen(VIRTUAL_WIDTH,VIRTUAL_HEIGHT,WINDOW_WIDTH,WINDOW_HEIGHT,{
fullscreen = false,
vsync = true,
resizeble= true,
})
end
function love.keypressed(key)
if key == 'escape' then
love.event.quit()
end
if key == 'enter' or key == 'return' then
temp1,temp2 = testTable[1][1],testTable[1][2]
--local tempx, tempy = temp1.x,temp1.y
--temp1.x,temp1.y = temp2.x,temp2.y
--temp2.x,temp2.y = tempx,tempy
temp3 = temp1
--temp1 = temp2
--temp2 = temp3
--temp1.x = 9
testTable[temp1.x][temp1.y] = temp2
testTable[temp2.x][temp2.y] = temp3
temp1.x = 9
testString = 'AFTER SWAP'
end
end
function love.update(dt)
end
function love.draw()
push:start()
local count = 1
love.graphics.print(testString, VIRTUAL_WIDTH/2,VIRTUAL_HEIGHT/2 - 20)
for k, element1 in pairs(testTable) do
for m,element in pairs(element1) do
count = count + 1
love.graphics.print(tostring(element.x)..tostring(element.y),VIRTUAL_WIDTH/2 + (count)*10, VIRTUAL_HEIGHT/2)
count = count + 1
end
break
end
love.graphics.print(tostring(temp1.x)..' '..tostring(temp1.y),0,VIRTUAL_HEIGHT - 50)
love.graphics.print(tostring(temp2.x)..' '..tostring(temp2.y),0,VIRTUAL_HEIGHT - 40)
love.graphics.print(tostring(temp3.x)..' '..tostring(temp3.y),0,VIRTUAL_HEIGHT - 30)
push:finish()
end
AFTER SWAP
12 91 13 14
91
12
91
My doubt is that , whether temp1,temp2 and temp3 have the values or references and how the interchange is working here. Please someone put some light on it.