Trying to get a way for the highest score scored to be constantly displayed

My score is based on collisions and involves this code:

– Add Score

local points = -20

scoreText = display.newText( " " … points,288, 225, Font, 20)
scoreText:rotate(90)
localGroup:insert(scoreText)

– Add Collision Event
squirrel.myName = “squirrel”
acorn.myName = “acorn”

– Collision detection! Explained below in detail
squirrel:addEventListener(“collision”, squirrel)

function squirrel:collision (event)
if event.other.myName == “acorn” then
points = points + 10
scoreText.text = "Score: " … points
local crack = media.newEventSound (“chop.wav”)
media.playEventSound (crack)
end
end

What should I add in order to create a text that says “High Score:(highest score printed here)”

that remembers all the scores done in the game over a lifetime and posts the highest score in this space? [import]uid: 71568 topic_id: 13051 reply_id: 313051[/import]

There’s two highscore demos in the code exchange, pick the one you like - it will show you how to save the highest score, update it when you need to and display it whenever you want - easy :slight_smile: [import]uid: 52491 topic_id: 13051 reply_id: 47961[/import]

– Highscore

local function save( event ) – function to save score
local path = system.pathForFile( “Highscore.txt”, system.DocumentsDirectory ) – where the file will be saved
local file = io.open( path, “w+b” ) – opening the file

file:write(Highscore …"") – writing the variable ‘score’ in the score.txt file
io.close( file ) – closing the file
– Saves our data

end

local function resumeStart()
local path = system.pathForFile( “Highscore.txt”, system.DocumentsDirectory ) – where the file will be saved
local file = io.open( path, “r” ) – opens the file under the variable file

if file then – if there is a file then
local contents = file:read( “*a” ) – read the contents of the file, and read the whole string(*a)

local prevState = explode(", ", contents) – put the contents of score.txt into a table
print(‘file’)
Highscore = prevState[1] – read the table at position 1 and assign the variable score

io.close( file ) – close file

else – if there is no file
Highscore=0 – the score then starts at 0
end
end

–ANSCA sample code–
function explode(div,str)
if (div==’’) then return false end
local pos,arr = 0,{}
– for each divider found
for st,sp in function() return string.find(str,div,pos,true) end do
table.insert(arr,string.sub(str,pos,st-1)) – Attach chars left of current divider
pos = sp + 1 – Jump past current divider
end
table.insert(arr,string.sub(str,pos)) – Attach chars right of last divider
return arr
end
–ANSCA sample code^–

resumeStart() – call the starting function

local scoretext = display.newText(‘Highscore:’,258,60,native.systemFont,20)
scoretext:rotate(90)
local t = display.newText(’’,258,80,native.systemFont,20) – score text
t.text=Highscore – update t to the score

save() – calls save, so when the user reloads the application the score is still there
t.text=Highscore – updates t to reflect new score

THis is what I have so far but it is not working properly, not showing the highest scoremade, is there something missing? [import]uid: 71568 topic_id: 13051 reply_id: 48855[/import]

I think what I need is a way to link my in game score (points) to my highscore does anyone know how to do this? I’m kind of new to corona.
[import]uid: 71568 topic_id: 13051 reply_id: 48887[/import]

maybe something like this? i tried it, im not so good in saving things and all, but maybe it will be of some help for you

i used a PropertyBag class for easy use, you should try it too
you can make some changes in my code and get what you want, maybe compare the scores made and put highest on top of the column or something like that, its still complicated for me))
good luck

[lua]local prop = require(“property”)

local propertyBag = prop:init()
local scoreTxt = display.newText("Score: ", 50,50, native.systemFont, 40)
local highscoreTxt = display.newText("Highscore: ", 50, 100, native.systemFont, 40)

local score = 0

function addscore()
score = score + 1
propertyBag:setProperty(“score”, score)
propertyBag:SaveToFile()
print(score)
scoreTxt.text = "Score: " … score
return score
end

timer.performWithDelay(1000, addscore, 22)

function showhighscore()
highscore = propertyBag:getProperty(“score”)
print(highscore)
highscoreTxt.text = "Highscore: " … highscore
end

showhighscore()[/lua]
[import]uid: 16142 topic_id: 13051 reply_id: 48893[/import]

The code I have is fine for locating the high score but I just need a way to link the score display to the high score display [import]uid: 71568 topic_id: 13051 reply_id: 48900[/import]