Using Score.lua and Mydata.lua HELP ME!

I want to save my score from this game.lua file:

I believe i have coded all of this correctly but, for some reason it doesnt save and display my high score on this window:

Please help me? I would appreciate it! All i want is to set scores based upon taps and then save those scores and display the best one in the restart windows! Any help will be much appreciated! Here are the Score.lua and Mydata.lua files.

Thanks for the Help!

Brady E. Pennington CEO of LongSword Entertainment

www.longswordentertainment.com

Working Score system from another Game:

Thant works but it looks exactly the same as the code i use in the new game that for some reason doesn’t work.

I’m not sure what the .rtf files are.  They couldn’t be opened with textEdit.

I just changed to .txt hope that makes it openable!

Brady E. Pennington CEO of LongSword Entertainment

Just a couple of observations.

  1. You’re making things global.  So you’re background in one scene will overwrite your background in the other.  You should "local"ize these.  If it needs to be global add it to the mydata table that you’re loading.

  2. Any code that’s in the scene’s main chunk like:

local physics = require( “physics” )
physics.start( true )

local sprite = require ( “sprite” )

local theme = audio.loadStream( “audio/Explosion.mp3” );

local storyboard = require (“storyboard”)
local scene = storyboard.newScene()

local score = require( “score” )

local mydata = require( “mydata” )

mydata.score = 0

Will only execute once.  When you return to this scene, the physics won’t re-start, mydata.score won’t be reset to 0, etc.   The “quick” solution is to call storyboard.removeScene() in your reset.lua rather than storyboard.purgeScene().  The proper thing to do is to move these items into the right functions so they happen each time the scene is re-entered.

As for the score, the idea behind  the score.lua module was to created to give you the display object to show the score.  You seem to be using it to create the high score and have a different display object to show the actual score. 

In your game.lua you don’t do anything with the score module.  You require it.  You create your own display and you’re tracking the score inside of mydata (really kind of bypassing the need for the score module).  You do try to call score.save(), but since you never initialized the module or told the score module what score to save, there isn’t anything to save.

Then in your restart.lua, you use the score module to create a high score object while creating your own display.newtext().  You look like you’re showing the score from mydata.score correctly, but immediately reset it to 0 in your enterScene().  You are populating bestscore.text from the score module via. score.get() but since you never populated it, there isn’t anything to get.

Rob

I am not having issues with the score resetting only Problems with it saving and displaying a High Score on the Restart Menu. I will include these 4 files from one of my other games in which this works.

Brady E. Pennington CEO of LongSword Entertainment

In your working model, you call the function loadScore() in enterScene(), in your non-working one, you do not.

Rob

Works Like a charm! Thanks Rob!

Brady E. Pennington CEO of LongSword Entertainment

I’m not sure what the .rtf files are.  They couldn’t be opened with textEdit.

I just changed to .txt hope that makes it openable!

Brady E. Pennington CEO of LongSword Entertainment

Just a couple of observations.

  1. You’re making things global.  So you’re background in one scene will overwrite your background in the other.  You should "local"ize these.  If it needs to be global add it to the mydata table that you’re loading.

  2. Any code that’s in the scene’s main chunk like:

local physics = require( “physics” )
physics.start( true )

local sprite = require ( “sprite” )

local theme = audio.loadStream( “audio/Explosion.mp3” );

local storyboard = require (“storyboard”)
local scene = storyboard.newScene()

local score = require( “score” )

local mydata = require( “mydata” )

mydata.score = 0

Will only execute once.  When you return to this scene, the physics won’t re-start, mydata.score won’t be reset to 0, etc.   The “quick” solution is to call storyboard.removeScene() in your reset.lua rather than storyboard.purgeScene().  The proper thing to do is to move these items into the right functions so they happen each time the scene is re-entered.

As for the score, the idea behind  the score.lua module was to created to give you the display object to show the score.  You seem to be using it to create the high score and have a different display object to show the actual score. 

In your game.lua you don’t do anything with the score module.  You require it.  You create your own display and you’re tracking the score inside of mydata (really kind of bypassing the need for the score module).  You do try to call score.save(), but since you never initialized the module or told the score module what score to save, there isn’t anything to save.

Then in your restart.lua, you use the score module to create a high score object while creating your own display.newtext().  You look like you’re showing the score from mydata.score correctly, but immediately reset it to 0 in your enterScene().  You are populating bestscore.text from the score module via. score.get() but since you never populated it, there isn’t anything to get.

Rob

I am not having issues with the score resetting only Problems with it saving and displaying a High Score on the Restart Menu. I will include these 4 files from one of my other games in which this works.

Brady E. Pennington CEO of LongSword Entertainment

In your working model, you call the function loadScore() in enterScene(), in your non-working one, you do not.

Rob

Works Like a charm! Thanks Rob!

Brady E. Pennington CEO of LongSword Entertainment