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 / Reading from files

Author
Message
elVee
21
Years of Service
User Offline
Joined: 4th Oct 2003
Location:
Posted: 7th Oct 2003 07:11
How exactly is it done?
Say your making a stratagy type game, and you want to store the unit info on a different file?
How should it be organized in the file?

like this?
(pretend first line is name, then attack, then defense, then cost)


and if so, how would you read one line, then move onto the next?

sorry if this a noobish question but Ive never really gotten the file reading and writing for any programming language really... Thanks in advance for any help.
PoHa!84
21
Years of Service
User Offline
Joined: 2nd Oct 2003
Location: To your left.
Posted: 7th Oct 2003 07:17 Edited at: 7th Oct 2003 07:18
For what your describing, I would probably use a couple of arrays (if I understood right...), but I think that after it reads the part of the data, then it moves on to the next, But I'm not 100% on that...
Maybe I helped though...

(P.S. Awesome graphic you got there...)

Destroy you with my mind, I could!
elVee
21
Years of Service
User Offline
Joined: 4th Oct 2003
Location:
Posted: 7th Oct 2003 07:30
I was planning on reading it to arrays, but I want it to be changeable after I made an executable.

As for the read part, how would I store one line (nothing more, nothing less) into an integer or string?
I looked at the help files, but I dont know how many bytes a single line would take.
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 7th Oct 2003 08:11
Ok, try this, i whipped it up to answer another Forum Question...

This is a string parser, if its not comented enough, just say and ill explain it.



And here is what is in the gamedata.txt file feel free to edit it and change it and add things to it all you like, thats what its for...




Hope I Helped...

PS if you need help using it, just post it and ill explain stuff to you

If Quizz's Are Quizzical, Then What Are Test's?
Check my profile for a quick test of knowladge...
PoHa!84
21
Years of Service
User Offline
Joined: 2nd Oct 2003
Location: To your left.
Posted: 7th Oct 2003 21:54
Err... I think I misunderstood, or maybe JessTicular misunderstood, so uh... yeah... and yeah some more... wait, what was I saying... oh yeah! Um, what about open to read, read byte, write byte, write word, etc...?
(I hope I don't have that part wrong...)

Destroy you with my mind, I could!
elVee
21
Years of Service
User Offline
Joined: 4th Oct 2003
Location:
Posted: 8th Oct 2003 05:24
Thanks for the help. Ill try the code now.

I hate the way file i/o works.
yea, thanks again
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 8th Oct 2003 07:38
PoHa!84, The best way to deal with character/weapons/world/NPC/AI data in external files is to set the file out like i have and then read the first line into a string and parse it to extract the relavant data, then read the second line into a string and extract the relavant data etc., etc.

Its just, the way that elVee wanted to do it:
Quote: "(pretend first line is name, then attack, then defense, then cost)

Archer
12
10
50"


Would mean that you could end up with a file that has litterally thousands of lines when it doesnt have to be...

You see, the way i set up the example, that was more for weapons than characters (but is easily modifyed) and you can see how if the file was set up like elVee suggested, you would end up with something like this:


That there is 31 lines compared to my example which is only 7 lines...

Hope I Helped...

PS If you dont understand the string parser that i have posted above, tell me and ill comment it more and put it back up...

If Quizz's Are Quizzical, Then What Are Test's?
Check my profile for a quick test of knowladge...
elVee
21
Years of Service
User Offline
Joined: 4th Oct 2003
Location:
Posted: 9th Oct 2003 04:09
I think I understand most of it... one thing though, in the line:

If item_data$(item_number,2) <> ""

why is there a <>?
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 9th Oct 2003 05:04
<> means not equal to
=! means the same thing in C++. The ! means not
elVee
21
Years of Service
User Offline
Joined: 4th Oct 2003
Location:
Posted: 9th Oct 2003 05:33
Yea I know a little c++.... I thought it meant the same as != in c++ but I wasnt sure... wanted to make sure
thanks
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 9th Oct 2003 11:23
So it all works and you understand it?

Good...

Knowladge Belongs To The People...
elVee
21
Years of Service
User Offline
Joined: 4th Oct 2003
Location:
Posted: 10th Oct 2003 02:33
Yea... I understand it...

but I dont understand HOW How does:
read string 1,string$
skip to the next line?
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 10th Oct 2003 07:56
Um, every time the Read String command is called, it reads the entire NEXT line of the file spcified...

That is, it reads the line into the string (string$) and then the next time the command Read String is called, it reads the next line (the line after the one just read) of the file into the string (string$) and so on...

Its just inbuilt into DB really...

Hope I Explained it properly...

Knowladge Belongs To The People...
elVee
21
Years of Service
User Offline
Joined: 4th Oct 2003
Location:
Posted: 11th Oct 2003 03:19
Ah yea... thanks for all the help
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 11th Oct 2003 10:09
Any time...

Knowladge Belongs To The People...

Login to post a reply

Server time is: 2025-05-20 17:22:43
Your offset time is: 2025-05-20 17:22:43