Creating a button to + or - 1 from a value

Hi there,

Having a simple issue here. I am trying to get a + and - button to either + or - a set value.

This is how I have coded it:


local qty = 0

local number = display.newText (qty, 50, 50, native, 30)

number.x = display.contentWidth/2

number.y = display.contentHeight/2

local plusButton = display.newImage (“plusButton.png”)

plusButton.x = display.contentWidth/2

plusButton.y = display.contentHeight/2-150

local minusButton = display.newImage (“minusButton.png”)

minusButton.x = display.contentWidth/2

minusButton.y = display.contentHeight/2+150

local function plusButtonTap (event)

      qty = qty+1

end

local function minusButtonTap (event)

      qty = qty-1

end

plusButton:addEventListener(“tap”,plusButtonTap)

minusButton:addEventListener("tap"minusButtonTap)


When I try to use this code, it does not add or subtract 1 as I have tried to get it to do in the application.

Have I missed something vital out, or do I need to se qty.tonumber? <- when I tried that it bugged out…

Thanks

Daine

number.text = qty

within each of the functions

T.

Thanks ToeKnee, problem resolved :slight_smile:

Why not consider the special widget built to do just that 

http://docs.coronalabs.com/api/library/widget/newStepper.html

Looks like the following and can be customized further.

widget-stepper.png

number.text = qty

within each of the functions

T.

Thanks ToeKnee, problem resolved :slight_smile:

Why not consider the special widget built to do just that 

http://docs.coronalabs.com/api/library/widget/newStepper.html

Looks like the following and can be customized further.

widget-stepper.png