How to display a dynamic “set numbers” ?

First, I apologize for the title I wrote. 
Actually I do not really know, a word that suits my problem.

 

Hi 
I’m making a game.
I want to display a “total score” in this case ‘total money’.

 

I’m making a game where the game will have a total money at first. 
And if players, buy some tools or materials, then this ‘total money’ will be reduced.
And vice versa, if players earn money, then this ‘total money’ will increase.

 

I want to ask,

  1. How to display the ‘total money’ I mean?
  2. How can this ‘total money’ increase or decrease?

 

Can you explain it with a simple app script?

 

I just started to learn corona sdk, a month ago.
Thanks.

Not tested as I’m at work but you get the idea.

  local totalMoney = 1000   local toolCosts = {spade = 50, bucket = 100, digger = 500} local moneyEarnt = {coin = 25, gem = 250, ruby = 1000}   local moneyText = display.newText(totalMoney, 50, 50, native.systemFont,16)     local updateMoneyText = function()     moneyText.text = totalMoney;     end   local buyItem = function (name)      if totalMoney \>= toolCosts[name] then        totalMoney = totalMoney - toolCosts[name]     updateMoneyText()     end     end     local findObject = function (name)     totalMoney = totalMoney + moneyEarnt[name]   updateMoneyText()     end   buyItem("spade") findObject("gem")  

Sounds like you are creating a new text object each time, can you post the code you have? The idea is to create once, and update whenever anything happens.

Yeah right, I want to make the text once and use it anywhere. I have several scenes.


Suppose the game.lua scene contains:

local totalMoney = 1000 local totalMoneyText = display.newText (totalMoney, 100, 100, native.Systemfont, 100) local updateMoneyText = function ()    totalMoneyText.text = totalMoney end local buyTools = function ()    if (totalMoney \>= hargaBlender) then      totalMoney = totalMoney - hargaBlender    end end

And, in the tools.lua scene contains:

local hargaBlender = 100 local buyBlender buyBlender = display.newImageRect (menuGroup, "scene / tool / buy-icon.png", 102, 56) buyBlender.x = 850; buyBlender.y = 565

The problem is, I want to make “buyBlender” into a button, which will call the “buyTools” function in another scene.

How to solve this?

Do I have a bad algorithm?

The simple answer is to read the API docs and tutorials. Everything you need is there - how to add event listeners to objects, how to reference other modules, transfer data between scenes etc.

I could write more code for you but this is all stuff I had to learn once by studying the docs, examples and other forum posts (via google searches), so there’s no reason why you can’t.

Not tested as I’m at work but you get the idea.

  local totalMoney = 1000   local toolCosts = {spade = 50, bucket = 100, digger = 500} local moneyEarnt = {coin = 25, gem = 250, ruby = 1000}   local moneyText = display.newText(totalMoney, 50, 50, native.systemFont,16)     local updateMoneyText = function()     moneyText.text = totalMoney;     end   local buyItem = function (name)      if totalMoney \>= toolCosts[name] then        totalMoney = totalMoney - toolCosts[name]     updateMoneyText()     end     end     local findObject = function (name)     totalMoney = totalMoney + moneyEarnt[name]   updateMoneyText()     end   buyItem("spade") findObject("gem")  

Sounds like you are creating a new text object each time, can you post the code you have? The idea is to create once, and update whenever anything happens.

Yeah right, I want to make the text once and use it anywhere. I have several scenes.


Suppose the game.lua scene contains:

local totalMoney = 1000 local totalMoneyText = display.newText (totalMoney, 100, 100, native.Systemfont, 100) local updateMoneyText = function ()    totalMoneyText.text = totalMoney end local buyTools = function ()    if (totalMoney \>= hargaBlender) then      totalMoney = totalMoney - hargaBlender    end end

And, in the tools.lua scene contains:

local hargaBlender = 100 local buyBlender buyBlender = display.newImageRect (menuGroup, "scene / tool / buy-icon.png", 102, 56) buyBlender.x = 850; buyBlender.y = 565

The problem is, I want to make “buyBlender” into a button, which will call the “buyTools” function in another scene.

How to solve this?

Do I have a bad algorithm?

The simple answer is to read the API docs and tutorials. Everything you need is there - how to add event listeners to objects, how to reference other modules, transfer data between scenes etc.

I could write more code for you but this is all stuff I had to learn once by studying the docs, examples and other forum posts (via google searches), so there’s no reason why you can’t.