Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Write File without a newline (CR) after each write?

Author
Message
Venatusio
12
Years of Service
User Offline
Joined: 6th Mar 2012
Location:
Posted: 26th Mar 2012 07:33
Hi,

Just adding a save function to my map editor.

This code works but it writes each value on a new line, I would like it to write the values across and not jump to next line until the end of the line (y increases)

So I can look at the save file and get an idea of what the level looks like. (I can of course load the file back into editor - but just curious from a programming perspective how I would approach this)

I tried a ; no joy.




Will I need to reinvent my save/load functions all together to use this approach?

Thanks all
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 26th Mar 2012 07:45 Edited at: 26th Mar 2012 20:04
Instead of writing a string for the value of Grid(x,y), why don't you write it as a WORD?



If the value of Grid(x,y) will always be less than 255, you could even write a BYTE instead of a WORD.

NOTE: If you change it to write either a WORD or BYTE, you should delete the current file, as it will have STRING data saved to it.

EDIT: My bad, I forgot to include the subroutine with it:



If you store the values as suggested and run this subroutine, it should print out the values, starting at 100,100.

So many games to code.......so little time.

TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 26th Mar 2012 11:06 Edited at: 26th Mar 2012 11:09
@LBFN

That would defeat the idea stated here:

Quote: "So I can look at the save file and get an idea of what the level looks like."


What you can do is stack all x values into a temporary string and then write it:



Keep in mind though that reading it will be a little harder now. A way to improve this is to make sure all strings have the same length by adding zero's at the front. For instance, 2 would become 0002. 42 would become 0042. 3784 would stay the same. The following code should do it (untested). I also made it add a space just for readability:



Reading it now makes it a lot easier because you know that every value is 6 digits long.

TheComet

Login to post a reply

Server time is: 2024-11-22 05:18:18
Your offset time is: 2024-11-22 05:18:18