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.

Newcomers DBPro Corner / Searching through a file?

Author
Message
Kafoolwho
4
Years of Service
User Offline
Joined: 16th Oct 2013
Location: The Deep
Posted: 11th Jan 2016 21:30
Hi again, everyone.

I find myself with a bit of a problem with my game I am working on. The game has 5 dungeons, with five levels each, which are randomly generated at the beginning of play, and then all map data saved to a single file, since I do not want to fill the player's save directory with 25 different files for each character they create.
This file is then used to read in the specific data of only the floor of the current dungeon they are in. This will also serve as the autosave file, so that when a player returns to the floor from somewhere else, all the level and enemy states remain as they left them on the previous visit.

My problem lies in loading the data relevant only to that floor. Each floor of the dungeon's data starts with a string holding the name of the dungeon and floor. Is there a way to search for, say, "Ruins B1" inside the file and loading only the data from there on out?

I remember back in the day when I still used QB 4.5 with DirectQB that there were commands specifically created for this, but I can't seem to find any equivalent in DBPro.

The other problem to trying to do this manually is that the size of the map data changes dynamically, adding new items, generating creatures etc. Since the file itself stores variables to denote the amount of changes done, the manual method is possible, but I would rather avoid unnecessary calculations and a bloated array with ALL the dungeon data loaded into memory.

Any tips, tricks, advice or shortcuts to this problem would be very much appreciated.
Phaelax
DBPro Master
14
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 22nd Jan 2016 20:14
Far as I remember, DBP doesn't have random access, but you could load the file into a memblock if needed.

You could write an integer before the map data stating the size of that map to follow. A simple file structure might look like this:

+ Code Snippet

So you could do something like:
+ Code Snippet

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
smerf
12
Years of Service
User Offline
Joined: 24th Feb 2005
Location: nm usa
Posted: 31st Jan 2016 07:12 Edited at: 31st Jan 2016 07:32
Easiest way I can think of is read string$ there's many many ways to sort through files. didn't realize phaelex had posted a second snippet + Code Snippet
A child\'s dream never dies.
Grog Grueslayer
12
Years of Service
User Offline
Joined: 30th May 2005
Location: Darkbasic Pro
Posted: 25th Apr 2016 08:08
It's been years since I posted but I am still singing the praises of IanM's Matrix1 Utilities Plugin. It has the ability to do random access files (binary files) just like Quickbasic. His File I/O commands allow us to open a file, change a specific byte or anything you need and close the file. Darkbasics native file commands force us to rewrite the entire file or load it into a memblock and save the whole file even if we only want to change a single byte. IanMs commands break the File I/O handcuffs off Darkbasic Pro.

Here's a link to the IanMs Matrix1 Utilities Plugin: https://forum.thegamecreators.com/thread/85209

Here's the help file for section 22 the File I/O commands: http://www.matrix1.demon.co.uk/Matrix1Utils_Help/Matrix1Util_22_index.html

Login to post a reply

Server time is: 2017-12-16 14:57:25
Your offset time is: 2017-12-16 14:57:25