I’m wanting it so that when I click a button It will have a popup at the bottom of the screen showing upgrade button. And if you tap the button again it will remove upgrade option. Right now I have
function cartTap( event ) if data.cartOpen == 0 then display.newImageRect( "upgrade.png", display.contentWidth, display.contentHeight ); data.cartOpen = data.cartOpen + 1 print("cartOpen = " .. data.cartOpen) end if data.cartOpen == 1 then display.remove( "upgrade.png"); data.cartOpen = data.cartOpen - 1 print("cartOpen = " .. data.cartOpen) end print("Open Cart Options") end
Right now it shows the upgrade option but if I press the button again it doesnt remove it and it adds the image again. In the console if I press it once it says
cartOpen = 0
cartOpen = 1
Open Cart Options
If I press the button again it just repeats that.
I’m wanting it so that when I click a button It will have a popup at the bottom of the screen showing upgrade button. And if you tap the button again it will remove upgrade option. Right now I have
function cartTap( event ) if data.cartOpen == 0 then UPGRADE = display.newImageRect( “upgrade.png”, display.contentWidth, display.contentHeight ); data.cartOpen = data.cartOpen + 1 print("cartOpen = " .. data.cartOpen) end if data.cartOpen == 1 then display.remove( UPGRADE); data.cartOpen = data.cartOpen - 1 print("cartOpen = " .. data.cartOpen) end print(“Open Cart Options”) end
Right now it shows the upgrade option but if I press the button again it doesnt remove it and it adds the image again. In the console if I press it once it says
cartOpen = 0
cartOpen = 1
Open Cart Options
If I press the button again it just repeats that.
I am by far no expert and have not done anything related to remove before - (usually get composer to handle that stuff) but i would check the docs about display.new….
I have added to your code above - an idea of the possible problem - the code may not work as adjusted - you will need to take the idea and adjust your own code.
But i do suspect that is the problem - UPGRADE = display…….
T.
Your function is adding 1 to data.openCart to make it 1. And then straight after it checks to see whether data.openCart = 1 and reduces it back down to 0. You need an else statement so it only runs one section of the code.
[lua]
function cartTap( event )
if data.cartOpen == 0 then
UPGRADE = display.newImageRect( “upgrade.png”, display.contentWidth, display.contentHeight );
data.cartOpen = data.cartOpen + 1
print("cartOpen = " … data.cartOpen)
else
display.remove( UPGRADE);
UPGRADE = nil
data.cartOpen = data.cartOpen - 1
print("cartOpen = " … data.cartOpen)
end
print(“Open Cart Options”)
end
[/lua]
I’m wanting it so that when I click a button It will have a popup at the bottom of the screen showing upgrade button. And if you tap the button again it will remove upgrade option. Right now I have
function cartTap( event ) if data.cartOpen == 0 then UPGRADE = display.newImageRect( “upgrade.png”, display.contentWidth, display.contentHeight ); data.cartOpen = data.cartOpen + 1 print("cartOpen = " .. data.cartOpen) end if data.cartOpen == 1 then display.remove( UPGRADE); data.cartOpen = data.cartOpen - 1 print("cartOpen = " .. data.cartOpen) end print(“Open Cart Options”) end
Right now it shows the upgrade option but if I press the button again it doesnt remove it and it adds the image again. In the console if I press it once it says
cartOpen = 0
cartOpen = 1
Open Cart Options
If I press the button again it just repeats that.
I am by far no expert and have not done anything related to remove before - (usually get composer to handle that stuff) but i would check the docs about display.new….
I have added to your code above - an idea of the possible problem - the code may not work as adjusted - you will need to take the idea and adjust your own code.
But i do suspect that is the problem - UPGRADE = display…….
T.
Your function is adding 1 to data.openCart to make it 1. And then straight after it checks to see whether data.openCart = 1 and reduces it back down to 0. You need an else statement so it only runs one section of the code.
[lua]
function cartTap( event )
if data.cartOpen == 0 then
UPGRADE = display.newImageRect( “upgrade.png”, display.contentWidth, display.contentHeight );
data.cartOpen = data.cartOpen + 1
print("cartOpen = " … data.cartOpen)
else
display.remove( UPGRADE);
UPGRADE = nil
data.cartOpen = data.cartOpen - 1
print("cartOpen = " … data.cartOpen)
end
print(“Open Cart Options”)
end
[/lua]