Help to make a Shop

Hi. I’ve been having a hard time implemting a shop in my game. What I’m trying to do is have upgrades in the game whenever the person has enough money to pay for it. I’m struggling to have the money subtract when the person has enough money. Here is the code is also plug and play

[code]require( “ice” )

bank = ice:loadBox( “bank” )

local amount = 0

local box = display.newRect(160, 240, 30, 30)

local bankText = display.newText(“0”, 160, 30,“Arial”,20)

local function change ()
if amount > 5 then
amount = -1
bank:increment( “total”, amount )
print(“bought”)
end
end
box:addEventListener(“tap”, change)

function endGame( )
bank:save()
bankText.text = “$” … bank:retrieve( “total” )
end

Runtime:addEventListener(“enterFrame”, endGame ) [/code]

Please help anyone thanks

:slight_smile: [import]uid: 17058 topic_id: 22073 reply_id: 322073[/import]

Haven’t been using Ice yet but shouldn’t line 13 be amount = -1 ?
Oskwish [import]uid: 24111 topic_id: 22073 reply_id: 87731[/import]

@oskwish oh forgot to put to say that I got it now this is how it looks for if people want to make a shop using ice or this code is very helpful to

[code]require( “ice” )

bank = ice:loadBox( “bank” )

local amount = 0

local box = display.newRect(160, 240, 30, 30)

local bankText = display.newText(“0”, 160, 30,“Arial”,20)

local function change ()
if bank:retrieve( “total” ) > 5 then
amount = -5
bank:increment( “total”, amount )
elseif bank:retrieve( “total” ) < 5 then
print(“not enough”)
end
end
box:addEventListener(“tap”, change)

function endGame( )
bank:save()
bankText.text = “$” … bank:retrieve( “total” )
end

Runtime:addEventListener(“enterFrame”, endGame ) [/code] [import]uid: 17058 topic_id: 22073 reply_id: 87733[/import]