File gets distorted on the way?

Just starting out? Need help? Post your questions and find answers here.
AJirenius
User
User
Posts: 29
Joined: Sun Aug 21, 2005 12:51 pm

File gets distorted on the way?

Post by AJirenius »

Ok this is what the code underneath is supposed to do:
First section saves all data in a Structureobject.
Next section just loads same data into another object based on the same structure. Now the first string reads well but all the "words" are messed up and when trying to show the words as str() it shows all kinda of numbers from -36726381 to +12378271 (approx ;) )

Now, am i not supposed to mix in writing a string in a file at first or is the problem somewhere else????

Code: Select all

Structure SDynamicGraphics
  Name.s
  ClipX.w[22]
  ClipY.w[22]
  ClipWidth.w[22]
  ClipLength.w[22]
  PosX.w[22]
  PosY.w[22]
EndStructure

        ;Save section looks like this
        ;Where Newsprite is a tempobject containing the data to be saved

FilNr=OpenFile(#PB_Any, Filename+".dat")
  WriteString (NewSprite\Name)
For n = 0 To 21
  WriteWord (NewSprite\ClipX[n])
Next n
For n = 0 To 21
  WriteWord (NewSprite\ClipY[n])
Next n
For n = 0 To 21
  WriteWord (NewSprite\ClipWidth[n])
Next n
For n = 0 To 21
  WriteWord (NewSprite\ClipLength[n])
Next n
For n = 0 To 21
  WriteWord (NewSprite\PosX[n])
Next n
For n = 0 To 21
  WriteWord (NewSprite\PosY[n])
Next n
CloseFile (FilNr)

; Now Loadsection looks like this and doesnt work (from the first Word-data)

FilNr=OpenFile(#PB_Any, "Data\"+DynGraphFileName+".dat")
  DynGraphics\Name=ReadString ()

  For n = 0 To 21
    DynGraphics\ClipX[n]=ReadWord ()    
  Next n
  For n = 0 To 21
    DynGraphics\ClipY[n]=ReadWord ()
  Next n
  For n = 0 To 21
    DynGraphics\ClipWidth[n]=ReadWord ()
  Next n
  For n = 0 To 21
    DynGraphics\ClipLength[n]=ReadWord ()
  Next n
  For n = 0 To 21
    DynGraphics\PosX[n]=ReadWord ()
  Next n
  For n = 0 To 21
    DynGraphics\PosY[n]=ReadWord ()
  Next n
  CloseFile (FilNr)


Now I erased some small codes which should not at all interfer with this.
Ive tested all data coming in and it really is the data that it says.
As it is "word-data" I cannot read it in a simple txt-viewer to see if the file is written correctly and only loaded badly or if it's problem with the savefunction.

Any suggestions? Any idea what Im even talking about here?
AJirenius
User
User
Posts: 29
Joined: Sun Aug 21, 2005 12:51 pm

Post by AJirenius »

OMG... dont tell me its a EndOfLine thingie in this one!!!

... damn... :evil: LOTS of work down the drain!

[EDIT]
Yes, that was the problem. Just writing it so if people are stumbling into the same problem you might get the solution right away ( and not stay ashamed like me :P)

If mixing up different types in a file make sure to make the command WriteStringN and not WriteString as ReadString read until EndOfLine and therefor corrupts the data sequences afterward the string :P
Post Reply