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.

Dark GDK / Save File

Author
Message
Tiomun
16
Years of Service
User Offline
Joined: 31st Jan 2008
Location:
Posted: 13th Mar 2008 11:18
I have been trying to get this to work for a while now. and i have read pretty much every post in the forums about saving any file, and encrypting them (like the random seed encrypt idea).
i have working scripts that save bmp's which work fine, but a .txt file for some reason will not work.

from what i have found in the dbpro and basic forums

something like

Should work that is pretty much how it seems to be done in the basic versions of db.

the dbMakeFile works just fine. i added it in to create the file then removed the command.
the file exists in the same folder as the script when run with dbMakeFile created it in, but when i try to write to the file nothing happens it remains void of nothingness and despair. lol

any help would be appreciated
Flashing Blade
22
Years of Service
User Offline
Joined: 19th Oct 2002
Location: United Kingdom
Posted: 13th Mar 2008 11:35 Edited at: 13th Mar 2008 11:37
Quote: "the file exists in the same folder as the script"


That may be your problem, IIRC OpenToWrite() will fail if the file exists.
You need to first check if file exists and delete if does ie:



I can't see any use at all for the command dbMakeFile()

Also why use the db file commands when you coding in c++?


The word "Gullible" cannot be found in any English Dictionary.
Tiomun
16
Years of Service
User Offline
Joined: 31st Jan 2008
Location:
Posted: 13th Mar 2008 12:32 Edited at: 13th Mar 2008 12:39
yep that did it. opening a file that dosnt exist and writing to it saves the file just fine.

i figured to write to a file the file had to exist first silly me. lol
I agree why have The dbMakeFile command, who would need an empty file you cant add anything to.

and for the whole why use db commands. well simply put im a noob at c++ and db still. and when ever i try to include c++ commands i seem to generate lots of errors lol


FOR other noob's to Refrence
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 13th Mar 2008 23:42
Good Reasons TioMan.

Stick to it... Hoever every so often look up LINKER ERRORS in this forum and general internet, then you might get through stuff like those linker errors you alluded to.

Good Luck.

jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 13th Mar 2008 23:54 Edited at: 13th Mar 2008 23:54
iirc, writing a string puts a CR/LF at the end of the string. Also, If you are writing floats, the file is no longer text, which explains why it does not do what you expect. (Assuming you want to view it with Notepad, for example.)
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 13th Mar 2008 23:56
But you can read float files with HEXEDIT, HEDIT I think its called.

Tiomun
16
Years of Service
User Offline
Joined: 31st Jan 2008
Location:
Posted: 14th Mar 2008 01:20
yeah i noticed that floats dont record as a actual number. any sugestion as to the best way to store a actual number? better yet when i read the float in my game from the file will it convert back to the actual number? if so its fine the way itr is. kinda like a semi encrypt func to it.

i also noticed the new line at the end of the str in the saved file. any way to remove that, or will it not affect anything. im not planing on having the file actualy open in notepad or anytext editor. actualy would like to prevent that lol. have a idea for a simple encrypt system.
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 14th Mar 2008 01:52
Just save as encrypted float and read back as encrypted float, you might get some variation but its float point inaccuracy...

the other way is to make a memblock four bytes wide, and use dbWriteMemblockFloat(ID,0,Value)

read into an integer
MyInt = dbMemblock(ID,0);
MyInt = SomeWeirdEncrypter(MyInt);
You can save it here, or force it back to float by putting it back in to memblock then reading it back into a float variable then save it! (OUCH) Lot of work BUT it describes a technique you should learn.

TYPE CASTING!!!!!

Type Casting lets you FORCE a value in a variable to be handled like a different data type. However your first curve ball is that when you type cast a INTEGER as a float or vice versa, its not ACTUALLY type casted, its converted for you... (or against you depending on your point of view LOL.)

Everything is REALLY a BYTE or a string of them - so type casting a FLOAT as a four byte array, and acecessing the 0,1,2,3 elements would allow you to tweak individual bytes. If you don't lose any bits (via lossful encryption versus good lossless scrambling) THEN you can get EVERYTHING BACK the same way in reverse.

Better still, you could write the data all to a memblock, and save the memblock in one fell swoop - encrpyed, binary, and ...well MESSED up for the casual Game MODDER or Media Pirate

jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 14th Mar 2008 02:36 Edited at: 14th Mar 2008 02:48
...or, just use sprintf, which will allow you to format a string any way you want, using any base, with any sort of input variable. Then, you store that string. Pie is 10 times more complicated.

As far as removing the CR/LF, you can byte bang it manually, or resort to using the aforementioned C/C++/Windows functions, which are better and faster. I have a DBPro version to write a null terminated string to a file, let me find it for you. You could duplicate it easily with the GDK, in case you want to keep using the GDK file I/O.

Login to post a reply

Server time is: 2024-11-20 05:38:47
Your offset time is: 2024-11-20 05:38:47