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 / File writing headaches

Author
Message
General Jackson
User Banned
Posted: 25th Nov 2010 05:42 Edited at: 25th Nov 2010 05:42
Master Man of Justice and I have been trying to figure this out.

We are trying to make it write objects position, rotation, and scale data to a file so that we can then read it later for loading maps.

I have tried all sorts of things and so has he.
Here is his code:

Now youll notice when you run this that it will write only the data for one object, and not all five.
How would we go about writing data for each object?

Thanks

soadjason
21
Years of Service
User Offline
Joined: 8th Apr 2005
Location:
Posted: 25th Nov 2010 06:28 Edited at: 25th Nov 2010 06:32
Hockeykid
DBPro Tool Maker
18
Years of Service
User Offline
Joined: 26th Sep 2007
Location:
Posted: 25th Nov 2010 06:38
Like this:



Please indent correctly

Master Man Of Justice
18
Years of Service
User Offline
Joined: 13th Feb 2008
Location: Between Insanity and Intelligence
Posted: 25th Nov 2010 07:11 Edited at: 25th Nov 2010 07:12
Thank you both!

Hockey, your code seems good for an advanced variable approach and probably will keep variable mismatching to a minimum.

Soad, your code demonstrated what i had done wrong all along.

While you guys were busy helping me i didnt check and came up with my own solution. I will get back with General and will decide which is best for the function.

Yet again, thank you both for your time and knowledge

(my code if you want to critique or use)


Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 25th Nov 2010 15:56 Edited at: 25th Nov 2010 16:01
Based on the Snippets:

You won't be able to retrieve the old data because the file is deleted at the top of the program.

I don't see why you would need to save the old data with the new data, since the new is all you'll need.

You need to retrieve the scale, not the size.

Master Man Of Justice, you have writestring loop inside another loop, meaning you'll end up with 5 times the amount of data. And everything else in there will be looped.

Two more examples:



Or:



A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
soadjason
21
Years of Service
User Offline
Joined: 8th Apr 2005
Location:
Posted: 25th Nov 2010 18:15
Quote: "You won't be able to retrieve the old data because the file is deleted at the top of the program."


Unless I misunderstood the question, General Jackson wants to read it later in the program when he is generating maps. If he is adding to old data he would also need to write to file how many objcts he is reading from, which I believe "write string 1,"Object "+str$(n+1) // not sure what you'd need this for." would be for.
DVader
22
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 25th Nov 2010 18:43 Edited at: 25th Nov 2010 18:48
Another simple method is to simply save the array directly, rather than making a file to rebuild it. If you are using types you would need IamM's utils to get round DB's array saving limits, or have to build a temp standard array and dump all the types in that, which kinda defeats the object.
I certainly find using load array "info.dat",info(), and save array "info.dat",info() and simply checking on load if the file exists, loading if it does and using default settings I set if not, easier than using files. It just saves doing the 'loading the file, deleting the file, make a new file' process.
Edit - oh one last thing using string arrays is more useful than the example I gave above , as you can store anything in them and convert as needed, unless you want people not to be able to read the file. Standard arrays seem fairly unreadable in comparison, although Db reads em just fine

http://s6.bitefight.org/c.php?uid=103081
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 25th Nov 2010 20:36
If you are going to output your values as strings to make the file readable/editable, then make it readable & editable. Lists of numbers are seldom readable in that way.

I suggest going the whole way - use your own take on this:


or


Writing parsers for simple stuff like that is fairly easy. For example, the first:


Also, if you are going to drive your program in this way, even if you don't make your output more structured in the ways I suggest, then I'd also suggest switching to my file I/O commands, as they are far faster.

Utility plug-ins (26-JUL-2010)
I'm applying terms of use that require you to wear a red nose and honk a horn whenever you use the Internet
Master Man Of Justice
18
Years of Service
User Offline
Joined: 13th Feb 2008
Location: Between Insanity and Intelligence
Posted: 26th Nov 2010 09:16
Hi Ian, thank you for your help, i download your matrix utils, and am currently being held back by my lack of knowledge and commonsense.

I've learned what Select(Case/Endcase)Endselect is used for but i seem to not understand what its doing.
What i am trying to do is this:


Read the values of the file before i open for writing.


Add those values to my array.


Then use my save function i have already written to save all objects in my array.


I think my problem is , the case statement checks to see if *one* of the values fits, then moves on.

here is my save function:



Here is my Read function:


here is all of the code together:


Im sorry if im blatantly asking you for code. But it is much appreciated.

Hockeykid
DBPro Tool Maker
18
Years of Service
User Offline
Joined: 26th Sep 2007
Location:
Posted: 26th Nov 2010 10:56
Yeah, don't use a separate array for each object variable. Use a type

Like this:



Master Man Of Justice
18
Years of Service
User Offline
Joined: 13th Feb 2008
Location: Between Insanity and Intelligence
Posted: 26th Nov 2010 17:45
thank you for the conversion hockeykid, i wasnt planning on using an array for each, but my bigger problem is still reading the file back.

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 26th Nov 2010 19:14 Edited at: 26th Nov 2010 19:15
Your problem lies with the line:


Every time you read a new line of data you increase the object id. You should only increase the object id when you encounter a new object in the file.

Here's something I've thrown together for you to study:


and here's a sample 'driver' file:


Utility plug-ins (26-JUL-2010)
I'm applying terms of use that require you to wear a red nose and honk a horn whenever you use the Internet

Login to post a reply

Server time is: 2026-07-21 12:49:34
Your offset time is: 2026-07-21 12:49:34