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.

DarkBASIC Professional Discussion / save game data as . txt or .dat

Author
Message
Battoad
AGK Developer
19
Years of Service
User Offline
Joined: 12th Feb 2007
Location: A Dark Place
Posted: 27th Feb 2011 19:02
Is it better to save game data as .txt or .dat ?
Apart from the obvious of being able to read .txt files
visually, what are the pros and cons ?

Thanks

Zotoaster
21
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 27th Feb 2011 21:15
No difference. Though .dat might make it clear that it's something that the game system uses and shouldn't be tampered with.

"everyone forgets a semi-colon sometimes." - Phaelax
Jammy
23
Years of Service
User Offline
Joined: 15th Jan 2003
Location: Scotland
Posted: 27th Feb 2011 21:17
I mostly save mine as .Jammysoft

You can still load them into notepad and edit as needed. But lets me know for sure at a glance files I have created, even years later.

I dont think it matters what you call them.

Westmere
16
Years of Service
User Offline
Joined: 12th Mar 2010
Location: Germany
Posted: 27th Feb 2011 22:02
The file extansions itself is just a first glance information what type of data a file contains. Today more for Windows or programs then for the user.

If a file has a .exe behind it Windows will treat it as an executable when you open it.
If it has a .txt Windows will load the Editor and tell it to open the file.
If it has a .dba Windows will load Dark Basic and tell it to open the file.

What's inside the file is a whole other story. If you rename a .exe file to .dat it won't run anymore although the file itself hasn't changed just because Windows THINKS it's something else. On the other hand most graphics programs can open a .jpg image from it's own menu (File => Open) even if it's called .dat.

Naming your saved files .txt is thus a bad idea since it denotes a Text document and Windows will open it with the Editor if a user clicks it which is something you usually wouldn't want. If it's a VERY large save file your system might even hang for a moment while the Editor tries to load it

My suggestion is to name savegames .sav. But you can name them whatever you like as long as you know what it is.

Battoad
AGK Developer
19
Years of Service
User Offline
Joined: 12th Feb 2007
Location: A Dark Place
Posted: 27th Feb 2011 23:17
Thanks for all yr inputs, very informative and useful.
I am mainly thinking of data saved e.g for high score tables, levels etc which will be part of my new Appup game. A .txt document is really easy for any user to "cheat" by editing the document, although he would only be cheating himself, but wondered if there were any other implications.
Thanks again for yr replies and any other comments appreciated.

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 27th Feb 2011 23:28
I'd do both, but isolate the load/save code in functions or subroutines. That allows you to use the txt version when debugging, but use the binary version in the public releases of your program.

Westmere
16
Years of Service
User Offline
Joined: 12th Mar 2010
Location: Germany
Posted: 28th Feb 2011 00:03 Edited at: 28th Feb 2011 00:20
Nope, no implications other then what Windows tries to open your file with.

If you want to keep using strings like you would put them into a text file but don't want them to be easily modifiable you can use my encryption routine I recently solved a small bug on this forum.

You can find it here.

Just make the two modifications mr_d suggested as they solve the bug I was posting about and prevent another one.
- Use a filter that consists of ALL the characters you need in your strings and make sure none of them are there twice. (That's what caused the bug in the threa - otherwise the decryption WILL screw up)
- Use a password that doesn't stick out in your executable as that will be visible in a text editor ^^
- For the key you can just use any jiberish you can think of.

As a result you have a simple text encryption that will turn even strings that are usually easy to decipher such as "AAAAAAA" into something like "e90j8q0" and will usually have attempts to fool with your data result in corrupted and thus unusable data ^^

Edit: Here's some actual save game data from my game (just an extract not a full save) so can see how much "jiberish" this encryption actually spits out:



Actually this stuff is mostly numbers and seperators ( ...it loads again without problems

Battoad
AGK Developer
19
Years of Service
User Offline
Joined: 12th Feb 2007
Location: A Dark Place
Posted: 28th Feb 2011 09:54
Wow, what a really good set of responses. You've given quite a few excellent options to try. Thanks to all.

BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 28th Feb 2011 17:00
I have another little cheat for you.

I use MD5 in IanM's Matrix utilities:

1. Write the data to the save file as text.
2. Use the MD5 Hash command on the data you save, all concatenated as one long string.
3. Verify the data when you load it using the MD5 Hash.

The cheat is this: If a specific value is found on line 1 of the save file, then I ignore the MD5 Hash. This means I can manually edit the data and add the secret code, but nobody else can. When I re-save the data, it removes the code.

Login to post a reply

Server time is: 2026-07-16 04:35:52
Your offset time is: 2026-07-16 04:35:52