score

here is my score i was wondering what storyboard fuination do i put it in to get rid of it in storyboard when restart screen opens

score = 0

 rightScoreBack = display.newImage(“scoreback.png”, 4, 15)

rightScoreBack.xScale = 4.5

rightScoreBack.yScale = 1.5

 scoreNumber = display.newText(score, 180, 0, nil, 50)

scoreNumber.xScale = .6

scoreNumber.yScale = .6

 function updateScore()

score = score + 1

scoreNumber.text = score

end

timer.performWithDelay(1, updateScore, -1)

 scoreText = display.newText(“score:”, 0, 0, nil, 50)

scoreText.xScale = .6

scoreText.yScale = .6

and how to i get restart and start screen to display you high score

At the top of your scene somewhere before createScene()

local score local scoreNumber   local function updateScore()     score = score + 1     scoreNumber.text = score end

I would put this block in your createScene() function:

local rightScoreBack = display.newImage("scoreback.png", 4, 15) rightScoreBack.xScale = 4.5 rightScoreBack.yScale = 1.5   scoreNumber = display.newText(score, 180, 0, nil, 50) scoreNumber.xScale = .6 scoreNumber.yScale = .6

how to i do high score and get the score to disappear on restart

hey wpcorley, to do the highscore i made it to save a .json file with the first score (with a if !filename to check if the file already existed) and then everytime the game ends compare the score saved in the .json with the new one, if it is bigger, replace them and save it into the file, i got the code from a tutorial from Rob Miracle (http://omnigeek.robmiracle.com/2012/02/23/need-to-save-your-game-data-in-corona-sdk-check-out-this-little-bit-of-code/)

I will let you read the tutorial and try to understand it, if you’re still lost after it, I will try to post my own piece of code to show you how could you do it! Good luck

Your score should reset back to 0 when you come back to the game scene, if it isnt then you could probably set it back to 0 yourself after you ended with the highscore comparations.

Hope it helps!

thanks il let you know if theres an issue

i have no idea what any of that means or how to change it to work on my code

hey wp sorry for the delay, this is what i do for my game and its working pretty good, i will try to explain step by step the best i can:

 myGameSettings = {} --"I create a new table that i will eventually save into a .json file" myGameSettingsOut={} --"I create an auxiliar table, that will READ from the file, to compare the current highscore with the new score" myGameSettings.highScore = globals.score --"I asign my score (global cause it came from another scene) to the table" if loadTable("mygamesettings.json") then --"This will control if the .json file already exist" myGameSettingsOut = loadTable("mygamesettings.json")--"Here i read the already existent file" if (myGameSettings.highScore \> myGameSettingsOut.highScore) then --"Comparation between new score and current highscore" saveTable(myGameSettings, "mygamesettings.json") --"If the new is bigger i save the table into the .json (overwriting the existing one)" local txt=display.newText("display new besthigh"..myGameSettings.highScore) group:insert(txt) else local txt = display.newText( "Best: "..myGameSettingsOut.highScore) --"I just print the current highscore if the new score is not bigger" group:insert(txt) end else --"If the .json file doesnt exist(first time i execute the code probably)" saveTable(myGameSettings, "mygamesettings.json") --" I just save the new score into the higscore since theres nothing to compare" local txt = display.newText( "New Best: "..myGameSettings.highScore) group:insert(txt) end

There is my code, i tried to explain what everything does there after the --, i hope you understand it now, of course for it to work u need to have these functions somewhere in your scene

local json = require ("json") function saveTable(t, filename) -- Function to save a table into a json file local path = system.pathForFile( filename, system.DocumentsDirectory) local file = io.open(path, "w") if file then local contents = json.encode(t) file:write( contents ) io.close( file ) return true else return false end end function loadTable(filename) -- Function to load a table from a json file local path = system.pathForFile( filename, system.DocumentsDirectory) local contents = "" local myTable = {} local file = io.open( path, "r" ) if file then local contents = file:read( "\*a" ) myTable = json.decode(contents); io.close( file ) return myTable end return nil end

Just copy paste them if you dont wanna understand them :stuck_out_tongue: and i suggest you to save those two cause you will probably need them everytime you work with external files (save scores, save settings like volumen, or username, etc)

I hope its a bit more clear now and i hope thats what you need. Did you fixed the score getting back to 0?

Edit: the display.newText things from my piece of code wont work probably cause i shortened them to fit in here, but im sure u know how to display text :slight_smile:

im sooo sorry in fact u don’t need to help me i should look my self

I’m only 11 and I’m almost done with my game but i looked around a little and i still understand nothing about saving score

maybe this will help. it hasn’t been updated for gpx2.0 yet but shouldn’t be hard to get working

http://j-strahan.com/main/?p=79

dose it cost money

no at bottom if page is link

it dosent work i have loads of errors apparently i can’t 

get anything to work other then that one score i put in the beginning of the discussion ugggg nothing works to save high score

i wiated a long time can somone tell me what or why it dosent work

At the top of your scene somewhere before createScene()

local score local scoreNumber   local function updateScore()     score = score + 1     scoreNumber.text = score end

I would put this block in your createScene() function:

local rightScoreBack = display.newImage("scoreback.png", 4, 15) rightScoreBack.xScale = 4.5 rightScoreBack.yScale = 1.5   scoreNumber = display.newText(score, 180, 0, nil, 50) scoreNumber.xScale = .6 scoreNumber.yScale = .6

how to i do high score and get the score to disappear on restart

hey wpcorley, to do the highscore i made it to save a .json file with the first score (with a if !filename to check if the file already existed) and then everytime the game ends compare the score saved in the .json with the new one, if it is bigger, replace them and save it into the file, i got the code from a tutorial from Rob Miracle (http://omnigeek.robmiracle.com/2012/02/23/need-to-save-your-game-data-in-corona-sdk-check-out-this-little-bit-of-code/)

I will let you read the tutorial and try to understand it, if you’re still lost after it, I will try to post my own piece of code to show you how could you do it! Good luck

Your score should reset back to 0 when you come back to the game scene, if it isnt then you could probably set it back to 0 yourself after you ended with the highscore comparations.

Hope it helps!

thanks il let you know if theres an issue

i have no idea what any of that means or how to change it to work on my code

hey wp sorry for the delay, this is what i do for my game and its working pretty good, i will try to explain step by step the best i can:

 myGameSettings = {} --"I create a new table that i will eventually save into a .json file" myGameSettingsOut={} --"I create an auxiliar table, that will READ from the file, to compare the current highscore with the new score" myGameSettings.highScore = globals.score --"I asign my score (global cause it came from another scene) to the table" if loadTable("mygamesettings.json") then --"This will control if the .json file already exist" myGameSettingsOut = loadTable("mygamesettings.json")--"Here i read the already existent file" if (myGameSettings.highScore \> myGameSettingsOut.highScore) then --"Comparation between new score and current highscore" saveTable(myGameSettings, "mygamesettings.json") --"If the new is bigger i save the table into the .json (overwriting the existing one)" local txt=display.newText("display new besthigh"..myGameSettings.highScore) group:insert(txt) else local txt = display.newText( "Best: "..myGameSettingsOut.highScore) --"I just print the current highscore if the new score is not bigger" group:insert(txt) end else --"If the .json file doesnt exist(first time i execute the code probably)" saveTable(myGameSettings, "mygamesettings.json") --" I just save the new score into the higscore since theres nothing to compare" local txt = display.newText( "New Best: "..myGameSettings.highScore) group:insert(txt) end

There is my code, i tried to explain what everything does there after the --, i hope you understand it now, of course for it to work u need to have these functions somewhere in your scene

local json = require ("json") function saveTable(t, filename) -- Function to save a table into a json file local path = system.pathForFile( filename, system.DocumentsDirectory) local file = io.open(path, "w") if file then local contents = json.encode(t) file:write( contents ) io.close( file ) return true else return false end end function loadTable(filename) -- Function to load a table from a json file local path = system.pathForFile( filename, system.DocumentsDirectory) local contents = "" local myTable = {} local file = io.open( path, "r" ) if file then local contents = file:read( "\*a" ) myTable = json.decode(contents); io.close( file ) return myTable end return nil end

Just copy paste them if you dont wanna understand them :stuck_out_tongue: and i suggest you to save those two cause you will probably need them everytime you work with external files (save scores, save settings like volumen, or username, etc)

I hope its a bit more clear now and i hope thats what you need. Did you fixed the score getting back to 0?

Edit: the display.newText things from my piece of code wont work probably cause i shortened them to fit in here, but im sure u know how to display text :slight_smile:

im sooo sorry in fact u don’t need to help me i should look my self

I’m only 11 and I’m almost done with my game but i looked around a little and i still understand nothing about saving score