Hi everyone,
I am trying to create a game where you can purchase upgrades for your units. To do this I have created a widget that will increase the level of the units, reduce the money the player has by the cost and increase the cost for the next upgrade. My problem is that I am unable to find a way to update the label of the widget automatically to show the new cost without reloading the scene.
Here is my code:
local function increaseWarriorLvl ( event ) if ( "ended" == event.phase ) then if mydata.money \>= mydata.warriorCost then mydata.money = mydata.money - mydata.warriorCost mydata.warriorCost = mydata.warriorCost + 10 mydata.warriorLv = mydata.warriorLv + 1 --warriorUpgrade:setLabel( "Upgrade Warrior " .. "$" .. mydata.warriorCost ) end end end local warriorUpgrade = widget.newButton( { label = "Upgrade Warrior " .. "$" .. mydata.warriorCost, onEvent = increaseWarriorLvl, emboss = false, shape = "roundedRect", width = 170, height = 50, cornerRadius = 2, fillColor = { default={0,0,0,0}, over={0,0,0,0} }, strokeColor = {default={1,1,1,1}, over={1,1,1,1} }, strokeWidth = 4, } ) sceneGroup:insert(warriorUpgrade) warriorUpgrade.x = cenx warriorUpgrade.y = ( toty/12 )\*3 warriorUpgrade:setLabel( "Upgrade Warrior " .. "$" .. mydata.warriorCost )
Whatever help is greatly appreciated.
Cheers,
Daniel