Android Question handmade txt file does not load in the file.readmap

Henry Baars

Member
Licensed User
Longtime User
Ok,
I give up… (almost)

I am using the map function in b4a to load a file with game levels.
When I programmatically generate the file with the Savelevelsmap sub I get the hex dump as shown below.

In this case the loadlevels sub works just fine.

But, when I create the file with a text editor and then convert it to get the vbLF (0A) correct, without any vbCR’s in the file, resulting in the !!! SAME !!! hex dump as shown below. Te APP crashes on the SECOND line in loadlevelsmap. The fist line is executed correctly. So, the simple conclusion:
something is wrong with the used parameter names of something is wrong with vbCr en vbLF.
But as the hex dump does show... parameter names are ok and there is only a VBLF between lines (which is exaclty what the File.WriteMap generates

The whole idea of the MAP function is that it is convenient to generate parameters in a txt document. But I like to generate them simply in a text file, without the need of programmatically generating it.

Any tips on how to use the map function with txt files I create manually, in stead of through code?
Sample code with an alternative (working) solution is also more then welcome.

Sub Activity_Create(FirstTime AsBoolean)
File.Copy(File.DirAssets, "gamelevels.txt", File.DirInternal, "gamelevels.txt")
End sub

sub Loadlevelsmap
LevelsMap = File.ReadMap(File.DirInternal,"gamelevels.txt")
Fairysprites1(0).x = LevelsMap.Get("1Levelx")
Fairysprites1(0).y = LevelsMap.Get("1Levely")
End sub

Sub Savelevelsmap()
LevelsMap.Put("1Levelx",100)
LevelsMap.Put("1Levely",100)
File.WriteMap(File.DirInternal, "gamelevels.txt", LevelsMap)
End Sub


C:\DOCUME~1\User\LOCALS~1\Temp\msohtml1\01\clip_image002.jpg
hexdump.jpg
 

Attachments

  • gamelevels.txt
    160 bytes · Views: 164

Henry Baars

Member
Licensed User
Longtime User
It works here:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim m As Map = File.ReadMap(File.DirAssets, "gamelevels.txt")
   Log(m)
End Sub


Sub Process_Globals
End Sub

Sub Globals
Dim LevelsMap As Map
End Sub

Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
File.Copy(File.DirAssets, "gamelevels.txt", File.DirInternal, "gamelevels.txt")
End If
loadLevelsmap
End Sub

Sub loadLevelsmap()
'Savelevelsmap
Dim x As Int, y As Int
LevelsMap = File.ReadMap( File.DirInternal, "gamelevels.txt")
x = LevelsMap.Get("2Levelx")
y = LevelsMap.Get("2Levely")
End Sub

Sub Savelevelsmap()
LevelsMap.Initialize
LevelsMap.Put("1Levelx",100)
LevelsMap.Put("1Levely",100)
File.WriteMap( File.DirInternal, "gamelevels.txt", LevelsMap)
End Sub

This is the shortest version I have. and it gives the error as shown in the screen dump attached
 

Attachments

  • screendump.jpg
    screendump.jpg
    234.1 KB · Views: 207
Upvote 0

Henry Baars

Member
Licensed User
Longtime User
The key name is 2levely not 2Levely.

Jez.... I really do need a new pair of glasses...:oops:
Maybe a new pair of brains as well...:cool:... maybe that was it... I have two eyes but only one brain to look with... no wonder I overlooked this one for over 5 hours!!!!

Erel... your a lifesaver.
Many thanks!
 
Upvote 0
Top