how to cancel a transition

I got it! I got it!!! YES!!!

Where you put the – transition.cancel(greenBar1Tween) – inside the doneButton.

I kept thinking,

"If here you cancel the transition, just make the green bar equal to the starting point.

and then make it invisible."

So I try in different ways – invisible first , the .x = 150 (it didn’t work)

I put it in a different way and it works!!!

local function doneButton ()         transition.to(done, {time=200, y=(centerY + 600)})         transition.to(song1, {time=100, x=opX, y=opY, xScale=1, yScale=1})         audio.stop ()         transition.cancel(greenBar1Tween)         greenBar1.x = 150         greenBar1.isVisible = false     end

Now when I stop the green bar, any time…

and I start the music again, the little green bar starts from the beginning…GREAT!!!

thanks for all your help.

I’m really proud of my self, I’m learning, I’m learning…

Programming is all about “what and how to do thinks? - code it later” :stuck_out_tongue: First you must state your problem. Think how you would do it, what you need and then write code :slight_smile:

I thought I got…sad…

something very strange is happening.

I have 2 green bars – one on top, one on the bottom.

----------THIS IS THE FIRST TIME I RUN THE CODE-----------

When I run the code the first time

the TOP green bar moves from x=1 to x=100

at the end

the BOTTOM green bar moves from x=1 to =100


if I cancel the transition on the BOTTOM first…

everything works fine, perfect.

I can reset the music and start all over and no problem

I can do it as many times as I want.


The problem is if I stop the transition on the TOP green bar.

I get a nil value – File: ? in line 75

here is where I have the cancel the BOTTOM green line


I don;t get it.

I changed – greenBar1Tween – for || reset1 || and || reset2 ||

local function doneButton ()         transition.to(done, {time=200, y=(centerY + 600)})         transition.to(song1, {time=100, x=opX, y=opY, xScale=1, yScale=1})         audio.stop ()         transition.cancel(reset1)         greenBar1.x = 150         greenBar1.isVisible = false         transition.cancel(reset2)         greenBar2.x = 150         greenBar2.isVisible = false     end

What is happening?

full code please

if not one thing, — it’s another …

you need to have a lot of patience for programming… a lot.

I admired you guys a lot.


I thought I might use an “if – else” statement. There I go.

local function doneButton () &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; transition.to(done, {time=200, y=(centerY + 600)}) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; transition.to(song1, {time=100, x=opX, y=opY, xScale=1, yScale=1}) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; audio.stop () &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if greenBar1.x \< 1000 then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;print ("this is the FIRST time") &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;transition.cancel(reset1) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;greenBar1.x = 150 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;greenBar1.isVisible = false &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; elseif greenBar2.x \< 1000 then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;print ("this is the SECOND time") &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;greenBar2.isVisible = false &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;transition.cancel(reset2) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;greenBar2.x = 150 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp; end

I try different forms, I think I have the idea…

I even put “print”

but in Terminal I don’t see the SECOND time

I guess it’s not detecting the – elseif ********* then

I don’t know why.

I really need help, I’m very close, but not yet!


sorry I did not see the “Full code please”

here it is.

local play1 = audio.loadSound ( "music1.mp3" ) display.setStatusBar( display.HiddenStatusBar ) local background = display.newImage("bg.png") local greenBar1 local greenBar2 local done local reset1 local reset2 local centerX = display.contentWidth / 2 local centerY = display.contentHeight / 2 local opX = 240 -- original placed .x local opY = 580 local tx1 = display.newText ("a Text messaging, or texting, is the act of typing and sending a brief, electronic message between two or more mobile phones or fixed or portable devices over a phone network. The term originally referred to messages sent using the Short Message Service (SMS); it has grown to include messages containing image, video, and sound content (known as MMS messages). The sender of a text message is known as a texter, while the se itself has different colloquialisms depending on itself has different colloquialisms depending on the region. It may simply be referred to as a text in North America, the United Kingdom, Australia an itself has different colloquialisms depending on the region. It may simply be referred to as a text in North America, the United Kingdom, Australia and the Philippines, an SMS in most of d the Philippines, an SMS in most of&nbsp; the region. It may simply be referred to as a text in North America, the United Kingdom, Australia and the Philippines, an SMS in most of rvice itself has different colloquialisms depending on the region. It may simply be referred to as a text in North America, the United Kingdom, Australia and the Philippines, an SMS in most of mainland Europe, and a TMS or SMS in the Middle East, Africa and Asia.a vea ver si le atinoaa ver si le atino ver si lea ver si le atino atinor se atinoea ver si le ata ver si le atinoino a vea ver si le atinoaa ver si le atino ver si lea ver si le atino atinor si le atinoatino", 30, 20, 452, 400, nil, 18) local song1 = display.newImage("music1.png") song1.x = opX song1.y = opY &nbsp;&nbsp;&nbsp; local function playSong () &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; transition.to(done, {time=200, y=(centerY + 340)}) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; transition.to(song1, {time=100, x=centerX, y=centerY, xScale=2.5, yScale=2.5}) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; greenBar1.isVisible = true &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; local function secondStaff () &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; greenBar1.isVisible = false &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; greenBar2.isVisible = true &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; reset1 = transition.to(greenBar1, {time=100, x=150, y=310}) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; local function smallFrame () &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; greenBar2.isVisible = false &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; transition.to(song1, {time=100, x=opX, y=opY, xScale=1, yScale=1}) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; reset2 = transition.to(greenBar2, {time=100, x=150, y=580}) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; reset2 = transition.to(greenBar2, {time=14800, x=1000, onComplete=smallFrame}) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; reset1 = transition.to(greenBar1, {time=14800, x=1000, onComplete=secondStaff}) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; audio.play(play1) &nbsp;&nbsp;&nbsp; end song1:addEventListener("tap", playSong) greenBar1 = display.newRect(0, 0, 7, 200) greenBar1:setFillColor(140, 255, 140) greenBar1.x = 150 greenBar1.y = 310 greenBar1.isVisible = false greenBar2 = display.newRect(0, 0, 7, 200) greenBar2:setFillColor(140, 255, 140) greenBar2.x = 150 greenBar2.y = 580 greenBar2.isVisible = false done = display.newImage("manzana.png") done.x = centerX done.y = centerY + 600 done:scale (.5, .5) &nbsp;&nbsp;&nbsp; local function doneButton () &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; transition.to(done, {time=200, y=(centerY + 600)}) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; transition.to(song1, {time=100, x=opX, y=opY, xScale=1, yScale=1}) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; audio.stop () &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if greenBar1.x \< 1000 then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;print ("this is the FIRST time") &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;transition.cancel(reset1) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;greenBar1.x = 150 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;greenBar1.isVisible = false &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; elseif greenBar2.x \< 1000 then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;print ("this is the SECOND time") &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;greenBar2.isVisible = false &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;transition.cancel(reset2) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;greenBar2.x = 150 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp; end done:addEventListener("tap", doneButton)

Thanks