how to show current score?

i have 2 scene “level1” and “gameover”

how to show current score at “gameover”?
just current score, not highscore or etc.

I wrote a module that can let you do this in one line of code. Very easy. I’m not on the PC right now. Do you have Skype?

@InfiSnyp : thx for reply… btw i dont hv skype, i hv poor internet :frowning:
u can send to my email later sir, pls
kali8pm@gmail.com

Well I don’t have documentation for the module yet. I might make an in depth video on it tonight.

@InfiSnyp : yes pls sir…
i need it so bad… ill watch ur video for sure :smiley:

see the photo below for instrucations 

What’s that for.?

@InfiSnyp : im still waiting ur answer/video tutorial sir :frowning:

Didn’t have time yesterday as it was Saturday. I will be able to record that video when everyone gets out of the house on Monday. Can’t promise anything though. 

Let me as some questions though.

Does your game use composer? Do you have scenes like

Main.lua --> menu.lua --> game.lua --> gameOver.lua --> (And so on)?

You might find this tutorial useful: https://coronalabs.com/blog/2013/12/10/tutorial-howtosavescores/

And as a ore-requist for that you might want to also read:  https://coronalabs.com/blog/2013/05/28/tutorial-goodbye-globals/

Corona supports multiple ways to share variables between scenes such as:

  1. Globals. This is generally considered a bad practice which leads to:

  2. Shared data table: This is what the Goodbye Globals tutorial covers. Basically you create your own “globals” that doesn’t have the issues with Globals!

  3. Composer variables: Composer has two methods:  :setVariable( key, value) and :getVariable( key ) that allows you to do what the shared globals does but you use the composer object. Pros: you don’t have to require the mydata.lua file everywhere. Cons: you don’t have direct access to the values and it’s a bit tougher to use for tables. Also if you have modules that don’t care about composer, it’s harder to get the data in and out of those modules (i.e you have to require composer even though you don’t use it)

  4. Composer parameter passing: When you call composer.gotoScene() you can pass a table of options. You can include an entry in the table called “params” which is another table of key-value pairs that composer.gotoScene() will pass to the composer events: scene:create() and scene:show().  The event table for those two event functions will have an event.params entry that is the params table you passed through composer.gotoScene()

  5. Use the score module in the first tutorial. This may be over kill, because it also attempts to manage the score display for you.

Using one of these techniques you can get access to your score variable that you updated in level1 in gameover and then you just create a normal display.newText() in gameover to display it.

Rob

@Rob : glad u answer sir…
but im still bit confused…

so i must put this code at level1 ?
[lua]
_G.score = 0
[/lua]

and at gameover i put this?
[lua]
score = _G.score
[/lua]

@InfiSnyp: yes sir… i have that scene but i still using storyboard.
menu>>selectLevel>>level1>>gameover(show score at lvl1)

If you’re going to use _G.score, just set it when you need to, it’s global and available everywhere. There is no need to do:

score = _G.score

_G.score is your value. If you’re using a display.newText() for instance in your game over you would do:

local finalScoreText = display.newText("Final score: " … _G.score, 150, 200, native.systemFontBold, 30)

But using _G.score means you are using a global variable. As long as you know you’re doing this and you know the ramifications of using it, then fine. In programming sometimes taking the simple route (and globals seem simple) leads to trouble later on.

Rob

You could also use a scene overlay and pass the score in as a param?  This works nicely if you implement it as a popover - like Candy crush, etc.

storyboard.showOverlay( “endgame”, {time=200, isModal=true, effect=“fromLeft”, params={score=1000}} )

and then in your endgame.lua read that value in the enter scene event with

local score = event.params.score

@Rob : nice its work!! thx sir…
i use one global each level…
but it seems i should learn to use modul later :smiley:

@adrianm : its nice to see overlay scene… makes apps more good… thx for ur advice sir :smiley:

I wrote a module that can let you do this in one line of code. Very easy. I’m not on the PC right now. Do you have Skype?

@InfiSnyp : thx for reply… btw i dont hv skype, i hv poor internet :frowning:
u can send to my email later sir, pls
kali8pm@gmail.com

Well I don’t have documentation for the module yet. I might make an in depth video on it tonight.

@InfiSnyp : yes pls sir…
i need it so bad… ill watch ur video for sure :smiley: