• Dear Cerberus X User!

    As we prepare to transition the forum ownership from Mike to Phil (TripleHead GmbH), we need your explicit consent to transfer your user data in accordance with our amended Terms and Rules in order to be compliant with data protection laws.

    Important: If you accept the amended Terms and Rules, you agree to the transfer of your user data to the future forum owner!

    Please read the new Terms and Rules below, check the box to agree, and click "Accept" to continue enjoying your Cerberus X Forum experience. The deadline for consent is April 5, 2024.

    Do not accept the amended Terms and Rules if you do not wish your personal data to be transferred to the future forum owner!

    Accepting ensures:

    - Continued access to your account with a short break for the actual transfer.

    - Retention of your data under the same terms.

    Without consent:

    - You don't have further access to your forum user account.

    - Your account and personal data will be deleted after April 5, 2024.

    - Public posts remain, but usernames indicating real identity will be anonymized. If you disagree with a fictitious name you have the option to contact us so we can find a name that is acceptable to you.

    We hope to keep you in our community and see you on the forum soon!

    All the best

    Your Cerberus X Team

WriteInt not numbers

Dubbsta

Active member
Joined
Jul 13, 2017
Messages
208
im writing from an array and i get symbols instead of numbers


Cerberus:
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
 
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.
 
thanks magic, i actually did writestring and worked but wasnt sure which was best. im just writing an array for map layouts
 
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:
@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
 
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:
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
 
  • Like
Reactions: mag
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

  • ascii.png
    ascii.png
    93.8 KB · Views: 217
Last edited:
Back
Top Bottom