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 / Two File Questions

Author
Message
Rwilson
23
Years of Service
User Offline
Joined: 19th May 2003
Location: United States
Posted: 2nd Oct 2003 01:38
First question. Is there any way to search an open file? Specifically, if I were to ahve a text file like so:

mnstr1
Evil Thing
1
12
15
mnstr2
Scaryness
1
16
11

Is there a way I could go to a specific tag (mnstr1,mnstr2) and read the info below it, much in the same way one would use a RESTORE command to read specific DATA commands?

Question 2. As one can see above, one must put his string variables within a text file on seperate lines to seperate them. Is there any way one could go about it a different way, such as:

mnstr1,Evil Thing,12,15
mnstr2,Scaryness,16,11

Thanks in advance!

Usermlsra - Causing Havoc with a Smile
Ian T
23
Years of Service
User Offline
Joined: 12th Sep 2002
Location: Around
Posted: 2nd Oct 2003 01:46
Question one: Read String will give you the next string line from a file. From there's, it's up to you to do whatever you want with that data, that includes determining the beginning of a monster definition, setting a variable, etc .

Question two: Using left$ and right$ to make your own search/locate function, yeah, it'd be possible.

So many file questions today... I think I might make a quick tutorial on this

--Mouse: Famous (Avatarless) Fighting Furball
Read It: http://www.angryflower.com/itsits.gif
Learn It: http://www.angryflower.com/bobsqu.gif
Rwilson
23
Years of Service
User Offline
Joined: 19th May 2003
Location: United States
Posted: 2nd Oct 2003 02:16
I think you might have misunderstood question 1. Thus, I will provide a more detailed explanation. Right now, I'm storing my monster data within the DBPro code like so.

Monster1
data "Scaryness",1,250,12,16
Monster2
data "Nasty Thing",2,400,16,18

I randomly choose a monster like so

monsterchoose = rnd(1)+1
if monsterchoose = 1 then restore Monster1 else restore Monster2
read name$,level,exp,str,dex

What I'm wanting to do, in an attempt to create a modibility into the program, is to store these stats within a text file. My question, specificly, is whether there is a way to move to a certain spot within an open file, much in the same manner as the Restore command. In this way, one can insert monsters, items, even spells without DBPro.

Thanks on Question 2. I'll have to work on that one a bit. Search engines are a new thing to learn, obviously .

Usermlsra - Causing Havoc with a Smile
BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 2nd Oct 2003 02:39
I use a file with a format like so:

M1Name=Scaryness
M1Id=2
M1size=200
M1Health=12

and I read it into a 2 dimensional array - variable name and value. I read the whole lot at the beginning of the program, and have a routine to locate the correct array element by name, and extract the value.

BatVink (formerly StevieVee)
http://facepaint.me.uk/catalog/default.php
Ian T
23
Years of Service
User Offline
Joined: 12th Sep 2002
Location: Around
Posted: 2nd Oct 2003 03:18
I just read up to the point in the file, but I suppose it's not optimal. In case you're wondering, though, I'm also using files for my monster data. I use different files for different monsters though... seems to work better for me.

--Mouse: Famous (Avatarless) Fighting Furball
Read It: http://www.angryflower.com/itsits.gif
Learn It: http://www.angryflower.com/bobsqu.gif
BillR
23
Years of Service
User Offline
Joined: 19th Mar 2003
Location: United States
Posted: 2nd Oct 2003 05:25
Hi, I'm not an expert in DB yet, but I will tell you what I understand about file access.

Using data statements and labels in DB lets you have RANDOM access to your data, which is very nice.

File reading is SEQUENTIAL access only. That means you have to read from the beginning, through the file to get any data you need.

What most people seem to do, is either read the entire file, parsing it into arrays as needed, or store data in individual files for each item, or monster in this case.

So far, I have stored most of my data in one file, reading in the file, and parsing it into arrays. I like having fewer files to edit, and parsing fewer files inside my program is my preference. But, having multiple files will work just as well if that's what you prefer. The more complex your files and objects are, the more files you should probably have.

If you need help parsing data in a file let us know, lots of people can help with examples.

Hope this helps.
Rwilson
23
Years of Service
User Offline
Joined: 19th May 2003
Location: United States
Posted: 2nd Oct 2003 07:31
BillR: Reading your info, I realize that I might change my plans a bit. Perhaps keep the offical monsters and such within data commands, and find some way of accessing the text files for User-Made items. Nontheless, It would do me good to understand the nature of file parsing, so yes, some help in understanding how to parse a files would be nice. I'm guessing it involves the left$ and right$ commands. Below is my own guess at how this would work:



The first sentance is the text file, the rest is the code. If this indeed the general idea as to how it would work, then I have one question. How would one going about ensuring that it reads an entire item? Several items, such as names and stats, can differ in length, thus making a hard coded number unusable.

Thanks all for the help so far. Hope I'm not being to much of a newb.

Usermlsra - Causing Havoc with a Smile
CattleRustler
Retired Moderator
22
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 2nd Oct 2003 07:36
(responding to original poster - all else unread)

...key...data...key...data...

INI files anyone?

look up win32api functions: GetPrivateProfileString(), WritePrivateProfileString()

-RUST-
Rwilson
23
Years of Service
User Offline
Joined: 19th May 2003
Location: United States
Posted: 2nd Oct 2003 08:40
Uh... what? I think you kinda lost me there, CattleRustler. Is the win32api a dll for DBPro? If so, could you at least give me the the area to search in? Sounds interesting, but there's at least 3 different areas something of that nature could go, and I think the new forum search engine hates me, cause it never seems to work right.

Usermlsra - Causing Havoc with a Smile
BillR
23
Years of Service
User Offline
Joined: 19th Mar 2003
Location: United States
Posted: 10th Oct 2003 07:40
Gone for a few days..If you don't have the code yet, here is some very simple code.



Hope this helps, just ask if you need more complex code.
BillR
23
Years of Service
User Offline
Joined: 19th Mar 2003
Location: United States
Posted: 10th Oct 2003 08:16
Went back and read your first post again, never did answer question#2, so here is that code.



I was getting tired, didn't test the code, if there is a problem let me know.
Rwilson
23
Years of Service
User Offline
Joined: 19th May 2003
Location: United States
Posted: 10th Oct 2003 16:04
Thanks BillR! Code is apprecicated!

Usermlsra - Causing Havoc with a Smile

Login to post a reply

Server time is: 2026-07-26 05:02:46
Your offset time is: 2026-07-26 05:02:46