Just a couple of observations.
-
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.
-
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