Array in at map

mrossen

Active Member
Licensed User
Longtime User
Hi

I am trying to make a highscore list.

I want to have only the five best scores. To to this I want to use a map to hold the five highscores an in each a string array with the name, score.

I think the code writes it right but the string array is empty when I try to read it again

Anyone have tried this?

Mogens


B4X:
Dim ScoreOne(), ScoreTwo(), ScoreTree(), ScoreFour(), ScoreFive() As String
Dim MapHighScore As Map
   MapHighScore.Initialize
   
   If File.Exists(File.DirInternal, "score.txt") Then 
   
      MapHighScore = File.ReadMap(File.DirInternal, "score.txt")
      
       For i = 0 To MapHighScore.Size - 1
         If MapHighScore.GetKeyAt(i) = "ScoreOne" Then ScoreOne = MapHighScore.GetValueAt(i)
         If MapHighScore.GetKeyAt(i) = "ScoreTwo" Then ScoreTwo = MapHighScore.GetValueAt(i)
         If MapHighScore.GetKeyAt(i) = "ScoreTree" Then ScoreTree = MapHighScore.GetValueAt(i)
         If MapHighScore.GetKeyAt(i) = "ScoreFour" Then ScoreFour = MapHighScore.GetValueAt(i)
         If MapHighScore.GetKeyAt(i) = "ScoreFive" Then ScoreFive = MapHighScore.GetValueAt(i)
       Next
      
   Else
      
      ScoreOne = Array As String("Tom", "")
      ScoreTwo = Array As String("Tom", "")
      ScoreTree = Array As String("Tom", "")
      ScoreFour = Array As String("Tom", "")
      ScoreFive = Array As String("Tom", "")
      
      MapHighScore.Put("ScoreOne", ScoreOne)
      MapHighScore.Put("ScoreTwo", ScoreTwo)
      MapHighScore.Put("ScoreTree", ScoreTree)
      MapHighScore.Put("ScoreFour", ScoreFour)
      MapHighScore.Put("ScoreFive", ScoreFive)
      
      File.WriteMap(File.DirInternal, "score.txt", MapHighScore)
      
   End If
 
Top