Having a bank score and adding on ?

hey I need help with something. Ok what I’m trying to do is have like a bank. What I’m trying to do is when you play a game your score adds up to your game you allready play like this example. Ok so you play 1 game and you score 10 points then the second game you play you score 30 points. Then now you have a total of 40 points like that. How would I do that with this example below

local score = 0  
  
local scoretxt = display.newText(score, 30, 30, "Arial", 30)  
  
local function up ()  
score = score + 1  
scoretxt.text = "Score :".. score  
end  
Runtime:addEvenListener("touch", up)  

Now how would I like make a bank score with using the above example, and save it [import]uid: 17058 topic_id: 21655 reply_id: 321655[/import]

My Ice library can probably help you there - http://developer.anscamobile.com/code/ice [import]uid: 5833 topic_id: 21655 reply_id: 85889[/import]

@graham This is not what I was looking for, what I want to know is how to save score like a bank.
So basically I play my game and it accumlates like a bank. Example, I have i won $10 in a game. Then I play another different game, and I won $20 now I have $30 saved from playing two different games. Now How would I do that? [import]uid: 17058 topic_id: 21655 reply_id: 85918[/import]

Using Ice:

main.lua

require( "ice" )  
  
bank = ice:loadBox( "bank" )  

game.lua ( or however you have structured your game )

function endGame( amountWon )  
 bank:increment( "total", amountWon )  
 bank:save()  
end  

winnings.lua ( or something )

print( "You have a total of " .. bank:retrieve( "total" ) .. " dollars." )  

[import]uid: 5833 topic_id: 21655 reply_id: 85920[/import]

@sebitttas,
you can also have it as complex as saving the scores for each type of game if you so wish.
So you can have,
Game1 -> 50 (10 + 20 + 10 + 10)
Game2 -> 30 (10 + 20)
Total -> 80

it is entirely upto you on how you want to structure this, all that the libraries do are save a number with a description that you can use to retrieve.

So you can save Game1 = 50
and retrieve the value in the file for Game1 , which will return 50

I hope you get the idea… [import]uid: 3826 topic_id: 21655 reply_id: 85936[/import]

@graham If you don’t mind give me a example code for how I want the bank please thanks [import]uid: 17058 topic_id: 21655 reply_id: 85945[/import]

@graham please again I would like an example of this would work thanks [import]uid: 17058 topic_id: 21655 reply_id: 85962[/import]

@graham what I mean an example is a fully functional working bank were game is over and the and money accumulate. I just need a simple thing that I can understand I need that small example for my project is very important to me. I don’t want snippets of code, I want a small plug and play code that works as a bank. I would appreciate that a lot

:slight_smile: [import]uid: 17058 topic_id: 21655 reply_id: 85967[/import]

@sebittas: Graham gave you a perfect sample to what you exactly needed.

You can’t expect people to write the whole game for you :slight_smile:

I suggest you try to learn from the examples available first, that will give you a good idea how Corona works.

[import]uid: 50459 topic_id: 21655 reply_id: 85989[/import]

rmbsoft is right :expressionless:

@sebitttas Your best bet is using Graham’s Ice library. It looks like the library functions do all the heavy lifting for you. In fact I’m downloading right now to start using it in the game I’m currently developing. [import]uid: 38820 topic_id: 21655 reply_id: 86005[/import]

@ sebitttas - 3 bump/reminder requests in the space of an hour? Some of us do sleep so can’t always get back to you straight away :slight_smile:

Ice is the small plug and play that works as the bank, you just have to hook it up to your game which I can’t really do without having written it.

@ rmbsoft - Thank you :slight_smile:

@ glennbjr - Hope you like it and it’s useful for you! [import]uid: 5833 topic_id: 21655 reply_id: 86051[/import]

@graham but then can you explain to me a little more how to add more money to the bank every time after a game, because I’m can you explain to me about this

[code]function endGame( amountWon )
bank:increment( “total”, amountWon )
bank:save()

print( “You have a total of " … bank:retrieve( “total” ) … " dollars.” )
end [/code]

Like what were did you get amountWon was it from the function or what? Can you explain to me this. I understand the print part. But not the function is confusing to me.

Like this is how I tried and do it, and it was coming out wrong

[code] require( “ice” )

bank = ice:loadBox( “bank” )
local amount = 0

local bank = display.newText(“0”, 30, 30,“Arial”,30)

local amountWon = display.newText("", 30, 60,“Arial”,30)

local function up ()
amount = amount + 1
amountWon.text = “” …amount
end
Runtime:addEventListener(“touch”, up)

function endGame( amountWon )
bank:increment( “total”, amountWon )
bank:save()
print( “You have a total of " … bank:retrieve( “total” ) … " dollars.” )
end[/code]

What is it that I’m doing wrong to my bank above?

P.S Also sorry for multiples post

[import]uid: 17058 topic_id: 21655 reply_id: 86083[/import]

In your above code you are passing a Display Object ( your text object ) into the endGame() function which needs a number.

The “amountWon” variable was just an example of how it could work, this would be whatever value you are trying to add to your bank after the end of the game. [import]uid: 5833 topic_id: 21655 reply_id: 86110[/import]

@graham not to be rude or anything but how would it properly look for the above code I just showed you [import]uid: 17058 topic_id: 21655 reply_id: 86113[/import]

Something like this:

[code]

require( “ice” )

bank = ice:loadBox( “bank” )

local amount = 0

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

local amountWonText = display.newText("", 30, 60,“Arial”,30)

local function up ()
amount = amount + 1
amountWonText.text = amount
bank:increment( “total”, amount )
end
Runtime:addEventListener(“touch”, up)

function endGame( )
bank:save()
print( “You have a total of " … bank:retrieve( “total” ) … " dollars.” )
end

Runtime:addEventListener(“touch”, endGame )

[/code] [import]uid: 5833 topic_id: 21655 reply_id: 86128[/import]

@graham thanks so much for the example very useful I appreciate your help a lot and patience with me :slight_smile: [import]uid: 17058 topic_id: 21655 reply_id: 86154[/import]

No worries, happy to help. [import]uid: 5833 topic_id: 21655 reply_id: 86184[/import]