How to use rawequal (value1, value2) to find the same coordinates and change the position of an object?

Something like this:

local object1 = display.newRect(100, 100, 50, 50)   --means object1.x = 100

local object2 = display.newRect(200, 100, 50, 50)   --means object2.x = 200

–During the objects dragging:

local function positionCheck ()

   if (rawequal (object1.x, object2.x) then

    transition.to (object1, {time=1500, x = object1.x - 50})

    transition.to (object2, {time=1500, x = object2.x + 50})

   end

end

In common, is it possible whithout “physics” library?

Thank you for some words to clarify it.

Yuriy

Hi.

rawequal is meant for something else; it ignores certain metamethods and checks if the “raw” objects are the same / different. (Maybe the particular object should be skipped, say, or the metamethod has a side effect.)

I suspect you’re dealing with coordinates that are almost, but not quite, the same. In that case, use a tolerance:

local function positionCheck () if (math.abs(object1.x - object2.x) \< .005 then -- close enough? transition.to (object1, {time=1500, x = object1.x - 50}) transition.to (object2, {time=1500, x = object2.x + 50}) end end

Thank you, StarCrunch!

Hi.

rawequal is meant for something else; it ignores certain metamethods and checks if the “raw” objects are the same / different. (Maybe the particular object should be skipped, say, or the metamethod has a side effect.)

I suspect you’re dealing with coordinates that are almost, but not quite, the same. In that case, use a tolerance:

local function positionCheck () if (math.abs(object1.x - object2.x) \< .005 then -- close enough? transition.to (object1, {time=1500, x = object1.x - 50}) transition.to (object2, {time=1500, x = object2.x + 50}) end end

Thank you, StarCrunch!