WriteInt not numbers

Joined
Jul 13, 2017
Likes
24
#1
im writing from an array and i get symbols instead of numbers


Cerberus X:
If KeyHit(KEY_ENTER)
                Local file:= FileStream.Open("cerberus://internal/map.txt","w")
            
                For Local i:Int = 0 Until level.map.Length()
                    If level.map[i] > -1
                        file.WriteInt(level.map[i])
                    End
                End
            file.Close()
            End
 
Joined
Mar 5, 2018
Likes
12
#2
I think WriteInt() will write to a file in bin so you will see ASCII symbol. May be use WriteString() if there available. I don't remember the function cos I'm away from my PC.
 
Joined
Jul 13, 2017
Likes
24
#3
thanks magic, i actually did writestring and worked but wasnt sure which was best. im just writing an array for map layouts
 

dawlane

Active Member
CX Code Contributor
Joined
Jun 21, 2017
Likes
192
#4
It shouldn't matter if what you use to write to a file, as long a you read the file back in the same manner. If you need to see which is best, then check the size for the file written. But it's always best to write data of in the same format as it's stored to save messing around converting from one format to another.
 
Last edited:
Joined
Mar 5, 2018
Likes
12
#5
@Dubbsta, which one best? actually not really much different here. Using writestring is more readable and can be edit easily by text editor but the size could be a bit bigger. if your array is huge then you might need to consider change.
Other thing... because its readable user can read it also..and change it manually.
in general, as @dawlane said, if you use writeint you need to use readint when you reading the file content later.

readint,readbyte and the like suitable for manipulate binary files
 
Joined
Jul 13, 2017
Likes
24
#6
makes sense thanks guys, just wasnt sure why i didnt see numbers but symbols, maybe ascii like you said magic havnt checked yet.
my new code so far i think this might be better to seperate the data out , it looks a lot better in txt though
Cerberus X:
If KeyHit(KEY_ENTER)
                Local file:= FileStream.Open("D:\Game Dev\practice\editor.data/map.txt","w")
          
                For Local i:Int = 0 Until level.map.Length()
                    If level.map[i] > -1 And level.map[i] < 10
                        file.WriteString("0" + String(level.map[i])+ " ")
                    Else file.WriteString(String(level.map[i])+ " ")
                    End
                End
            file.Close()
            End
 
Joined
Mar 5, 2018
Likes
12
#7
Edited:
just wasnt sure why i didnt see numbers but symbols
Like many other thing in computer, all is actually binary. So when you writeInt() you are actually write it in binary.

Say you want to writeInt the value of 100 to the file. In binary it is 1100100.

Since cerberusX integer is a 32 bit or 4 bytes, it will look something like this:
00000000,00000000,00000000,01100100

Or if you looking at it as decimal in byte size you will see:
0,0,0,100
This is actually the value written to the file in binary.

When we open that file in text editor, the program is force to display something represent the content of the file. Normally the editor program will show the ASCII code represent by the byte.

ascii.jpg

So according to the ASCII chart above, you might end up seeing <?>,<?>,<?>,d
 

Attachments

Last edited:
Top Bottom