how to randomize transitions

Hey,
So I have this transitions and I want them to randomly be activated. And then, once I tap the object, the transition get cancelled. Here’s my code:

local object1 = display.newImageRect ("object1.png",80,40)  
 object1.x =40; object1.y = 30  
  
local object1 = display.newImageRect ("object1.png",80,40)  
 object1.x =40; object1.y = 90  
  
local object1 = display.newImageRect ("object1.png",80,40)  
 object1.x =40; object1.y = 150  
  
 local trans1 = transition.to(object1, {time = 2000, x = 100, y=30})  
 local trans2 = transition.to(object2, {time = 2000, x = 100, y=90})  
 local trans3 = transition.to(object3, {time = 2000, x = 100, y=150})  
  
 local function onTouch(event)  
 transition.cancel(trans1)  
 transreverse = transition.to(object1, { time = 200, x=40, y=30})  
 end  
object1:addEventListener("tap", onTouch)  
  
local function onTouch2(event)  
 transition.cancel(trans2)  
 transreverse2 = transition.to(object2, { time = 200, x=40, y=30})  
 end  
object2:addEventListener("tap", onTouch2)  
  
 local function onTouch3(event)  
 transition.cancel(trans3)  
 transreverse3 = transition.to(object3, { time = 200, x=40, y=30})  
 end  
object3:addEventListener("tap", onTouch3)  

Right now they all start transitioning at the same time…I need them to start one at a time, randomly, and stop after I tap each of them. Once they’re back to the original place (x=40), I need them to reenter into the random function to start transitioning again.

Any thoughts?
Tks

[import]uid: 95495 topic_id: 18826 reply_id: 318826[/import]

its not pretty, but i’m sure you can adjust my code for your means)

[lua]local activate

local obj1 = display.newRect(0,0,50,50)
obj1.x0 = obj1.x
obj1.y0 = obj1.y
local obj2 = display.newRect(0,0,50,50)
obj2:setFillColor(255,0,0)
obj2.y = 70
obj2.x0 = obj2.x
obj2.y0 = obj2.y

local obj3 = display.newRect(0,0,50,50)
obj3:setFillColor(0,255,0)
obj3.y = 150

obj3.x0 = obj3.x
obj3.y0 = obj3.y

local function onTouch(self,event)
if event.phase == “ended” then

self.x = self.x0
self.y = self.y0

activate()
end
return true
end

obj1.touch = onTouch
obj2.touch = onTouch
obj3.touch = onTouch

obj1:addEventListener(“touch”, obj1)

obj2:addEventListener(“touch”, obj2)

obj3:addEventListener(“touch”, obj3)

math.randomseed(os.time())

local function one()
local trans1 = transition.to(obj1, {time=1000,x = 300})
end
local function two()
local trans2 = transition.to(obj2, {time=1000,x = 300})
end
local function three()
local trans3 = transition.to(obj3, {time=1000,x = 300})
end
function activate()
local mRand1 = math.random(1000,5000)
local mRand2 = math.random(1000,5000)
local mRand3 = math.random(1000,5000)
if obj1.x == obj1.x0 then
timer.performWithDelay(mRand1, one,1)
end
if obj2.x == obj2.x0 then
timer.performWithDelay(mRand2, two,1)
end
if obj3.x == obj3.x0 then
timer.performWithDelay(mRand3, three,1)
end
end
activate()[/lua] [import]uid: 16142 topic_id: 18826 reply_id: 72469[/import]