Android Question Trying to read file from a BlitzBasic program

andymc

Well-Known Member
Licensed User
Longtime User
I am trying to read in data from files created using the blitzbasic language on PC. Blitz is meant to write 2 bytes at a time for int values, which is all the file contains, however when I try to read these values using the randomaccessfile library in B4A I get garbage coming out.

The first integer value in the file is the number of trees on a level, blitzbasic says it uses 2 bytes amounts for int values, which is great, as the randomaccessfile library does too, except this doesn't seem to be working. The number of trees b4a is reporting that it's finding is 1073741824, which is slightly higher than the 50 or 60 I was expecting. So then the next stage of level loading is to carry on and load the position of these trees, each one stores the x value then the y value of the coordinate in the file, these values are also all read in as garbage until the file runs out and I get a bufferunderrun exception.

Any ideas?

I've attached the file.
 

Attachments

  • level1a.txt
    1.3 KB · Views: 213

sorex

Expert
Licensed User
Longtime User
are you sure it's 2 bytes and not 4? I get a lot of 0s inbetween values.

B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private TabPane1 As TabPane

Dim buffer(2000) As Byte
Dim bcount As Int
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("main") 'Load the layout file.
    MainForm.Show

buffer=Bit.InputStreamToBytes(File.OpenInput(File.DirAssets, "level1a.txt"))

For x=0 To 20
Log(readValue)
Next
End Sub

Sub readValue As Int
Dim v As Int
v=buffer(bcount)+(buffer(bcount+1)*256)
bcount=bcount+2
Return v
End Sub

Program started.
64
0
572
0
315
0
282
0
251
0
388
0
606
0
152
0
646
0
424
0
1117
 
Upvote 0

andymc

Well-Known Member
Licensed User
Longtime User
Thank you so much Erel!!!! You're brilliant!!!! That solved it, it was the endianess parameter, I can still use readint but had to change it to littleendian

This means I can use my existing game level editor written in BlitzBasic to design the levels for my B4A game, this is awesome!

Sorex: yeah I saw that when I opened the file in a hex editor, not sure what they are unless their somekind of stop bytes in the encoding maybe?
 
Last edited:
Upvote 0
Top