Game Programming‎ > ‎FlappyBird‎ > ‎

Flappy Bird - Saving Scores

You Can Save High Scores From Game To Game


1. On gameOver, Ask their name and save their score

    In the gameOver code, add the following:

// handle game over condition
on gameOver
   answer "You crashed, game over "
   set the bottom of btn "bird" to 400
   ask "What is your name?"
   if it is not empty then 
      
put it into theName       

      put specialFolderPath("Documents") & "/Scores.txt" into myFile
 
      put URL ("file:" & myFile ) into highScores
      put theName & tab & field "score" & return after highScores
      put highScores into URL ( "File:"
& myFile)
   end if

end gameOver

2. To See All the High Scores, add a button "Scores" and put the following into the script of the button:

on mouseUp
   put specialFolderPath("documents") & "/Scores.txt" into myFile
   set itemDelimiter to tab

   put  url ("file:" & myFile)    into    x
   sort lines of x numeric descending by item 2 of each
   answer x
end mouseUp


Comments