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 Discussion / saving object position into .txt file..

Author
Message
Shafan
21
Years of Service
User Offline
Joined: 22nd Dec 2003
Location: israel
Posted: 7th Apr 2004 19:24
i want to save objects location into .txt file...
how do id do it?
i make a level editor program and i close to the end...i just need to save the details of the object location,size etc..
but how do i write real number into string?
thankssss
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 7th Apr 2004 22:53
don`t use strings, what would be the point?, write the real number to the file as a real number, eg

open to write 1,"SavedData.GDT"
write float 1,PositionX#
write float 1,PositionY#
write float 1,PositionZ#
write float 1,ScaleFactor#
close file 1

then to load em back just do

open to read 1,"SavedData.GDT"
read float 1,PositionX#
read float 1,PositionY#
read float 1,PositionZ#
read float 1,ScaleFactor#
close file 1

no need for cumbersome conversion to strings etc, but if you MUST use strings then just use STR$ to convert the numbers to strings and then save them, eg:

value$=str$(number#)

cheers.

Mentor.

PC1: P4 hyperthreading 3ghz, 1gig mem, 2x160gig hd`s, ATI radeon 9800 pro gfx, 6 way surround sound, PC2: AMD 1.2ghz, 512mb ram, FX5200 ultra gfx, stereo 16 bit soundblaster, ups.
Shafan
21
Years of Service
User Offline
Joined: 22nd Dec 2003
Location: israel
Posted: 8th Apr 2004 20:58
thanks....thw two ways are been very useful to me...
Shafan
21
Years of Service
User Offline
Joined: 22nd Dec 2003
Location: israel
Posted: 9th Apr 2004 16:42
can you tell me litle about .GDT file?
i use the string way to export the level details into a .txt file
and i want to use the .GDT file to save the level...
and i never work wuth this file...
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 9th Apr 2004 18:56 Edited at: 9th Apr 2004 19:37
all it is is a way to identify the file as one you/I made, GDT is a contraction of Game DaTa, I used it to make it easy to find any game data saves, when your programs get larger and you have level data and encrypted media files etc in the folder, you know a GDT file is saved game data, you can make up your own "file format", for example GDT files save the position and scale of the player as four floating point numbers, if you want to add more data to the savegame file then feel free to go ahead, you could even save your data as .SGD (Shafan Game Data), one of the cool things about being a coder is you can get to make your own designer file formats named after your own humble self
for example you could save your text file but instead of using the .txt ending, you could save it as "gamedata.DVD" (Digital Videogame Data )or "gamedata.abc" or "gamedata.nakedhamster" or whatever you please (though your helpline would get a lot of weird calls about the "nakedhamster" file format), the habit of using three letters to identify filetype goes back to DOS days when you where allowed eight letters for the filename and three to identify the filetype, so all computers had files like gvmntrpt.txt or topsecre.txt, nowdays the filesystem can handle larger extensions but people stick to 3 characters for backwards compatability (although only people with windows 3.1 or dos are going to appreciate this )
In summary .GDT was something I just made up on the spur of the moment since I had to call the file something, since it`s a custom file I could have just called it "savegame" and left off the file extension. but extensions allow you write code to list all the saved games for your player to select one etc, much more useful than trying to work out if "somethingimportant" was a save game file or the users ID or the network settings or a music file etc, to make a save game file all you have to do is write all your data in order then read it back in the same order, you can add a few numbers to confuse hackers and check for altered files to stop loading if someone tries to cheat etc, it`s all up to you.
heres a simple example, I want to save the game state and hi-score table for a simple shooter game, I want to save the level, the number of current enemies and the players health and position, plus the top 5 scores, all I do is something like this

open to write 1,"supergame.savedata" <<< creates a file with this name
write word 1,level <<saves the level number
write word 1,enemies <<number of enemies
write word 1,health <<current health of the player
write word 1,position x
write word 1,position y <<<the x and y positions of the player
for i=1 to 5 << now we write out the score table
write long 1,hi(i) <<the score
write string 1,hi$(i) <<the players name
next i
close 1 <<finished with the file, this is the end of it

then all you have to do is to go through the list in the same order and load them back to the same values, and thats your home made file format, there is nothing to stop you doing

open to write "textfile.txt"
for i=1 to 5000
write word 1,rnd(255)
next i
close 1

which will make an unreadable .txt file on your hardrive, what it does is save numbers in a file called .txt, but not in txt format, so word thinks it`s a text file cos of the extension, and tries to read it, all you see is gibberish, a mixture of letters and numbers, since word can`t understand the file, hope that explains it somewhat.

Mentor.

PC1: P4 hyperthreading 3ghz, 1gig mem, 2x160gig hd`s, ATI radeon 9800 pro gfx, 6 way surround sound, PC2: AMD 1.2ghz, 512mb ram, FX5200 ultra gfx, stereo 16 bit soundblaster, ups.
Shafan
21
Years of Service
User Offline
Joined: 22nd Dec 2003
Location: israel
Posted: 9th Apr 2004 21:02
thank you very much....
now i understand all...
this is very useful information...
you help me alot to almost finish my "level editor" program..
i just have to do some visual details and i done..
thanks you...

Login to post a reply

Server time is: 2025-05-23 06:49:51
Your offset time is: 2025-05-23 06:49:51