0

i have a table(array) where i keep the references of some images. Here is the code: local rowcount = 8 local colcount = 4

    local blockWidth = display.contentWidth / (colcount*4)
    local blockHeight = display.contentWidth / (rowcount*2)

    local row
    local col
    local pan = 3
    local i=0
    for row = 1, rowcount do
            for col = 1, colcount do
                    local x = (col - 1) * blockWidth + pan + 30
                    local y = (row + 1) * blockHeight + pan
                    local random= math.random(1,6)
                    random = revisarTres(i, random)

                    local image = display.newImage(images[random], 0, 0)
                    image.x = x
                    image.y = y
                    print (x)
                    print (y)
                    image.value = random     
                    image:addEventListener("touch", blockTouch)
                    block[i] = image




                    i=i+1
            end
    end

I keep the references in block of my 31 images.

Then i make a transition for one image to another, conversely. And i want to change the value, the coordenates and the reference of this two. I'm making this:

          block[old].value, block[new].value = block[new].value, block[old].value                

          block[old].x, block[new].x = block[new].x, block[old].x

          block[old].y, block[new].y = block[new].y, block[old].y

          block[old], block[new] = block[new], block[old]

Old is the position of one of the images i want to change and new of the other one.

The reference is changing but the value doesn't.

Please can someone help me,

Thanks!

Rodrigo López
  • 227
  • 4
  • 17

1 Answers1

1

One small note (addition?):

if You ever find a table, where You can't directly change values - check if it's not readonly one. More about this kind of technique using Lua metatables: lua-users Wiki - Read Only Tables

Kamiccolo
  • 7,758
  • 3
  • 34
  • 47