Jump to content
  • Advertisement
Sign in to follow this  
MrSplosion

Moving Pointer to When Writing to File

This topic is 2398 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm writing raw bytes to a file for something I'm working on. I'm having difficultly trying to format the file though. I want to write the bytes down in a column then move back to the top to write the next column. This it what I wan't it to look like. But for some reason it looks like this. Here is my script:



function WriteToFile(){

var file = StreamWriter(Application.dataPath + "/data/saveWorld.txt", true);

for(i = 0; i < 10; i++){

file.WriteLine("z"[0]);

if(i >=10){

file.BaseStream.Seek(i, SeekOrigin.Begin);

}

}

file.Close();

}

Share this post


Link to post
Share on other sites
Advertisement
What language is this? That kind of information is important, you should probably learn to give that up front.


for(i = 0; i < 10; i++){
...
if(i >=10){


If your loop only goes to 9, then when exactly is this if statement supposed to evaluate to true?


file.WriteLine("z"[0]);


WriteLine implies that is appends a newline character sequence to everything. You don't want that.

Share this post


Link to post
Share on other sites
AFAIK, file streams, or any other streams I know of, aren't able to insert data. What I recommend doing is either first transform the data into the desired format using a string or something and then writing that string to the stream, or change the way you iterate over the data (instead of column by column, row by row, why not row by row then column by column?).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!