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 / Help with level data organisation/storage

Author
Message
Tinkergirl
21
Years of Service
User Offline
Joined: 1st Jul 2003
Location: United Kingdom
Posted: 1st Jul 2003 16:48
Hi,

My friend and I are working on a 'netrunning' kind of game - our first big attempt. However I've come to my first really big stumbling block (there have been little ones . I hope someone can help.

I'm trying to set up a level structure, where each level contains certain unique objects, placed in particular places. Some of these objects then link to other levels - much like the 'box in a box' description of arrays.
However each object in the level has approx seven 'nuggets' of information associated with it - like coordinates and strength values (numerical) and type, level-linked-to and unique name (strings). Of course, some object 'types' have null values for some of the nuggets. I don't know yet, but I think I might need a 'nugget' for each object that points to it's 'parent' object too.

So what I need (/want?) is a way (preferably) of being able to save and load a file for each level's information, using the variable of the level-linked-to of the parent object as the name of the file.

Of course, to make matters worse, I'd really like to make it as open-ended as possible for future expansion - just in case I need new/additional nuggets of information, and to allow for as many or as few levels as is required. And I want to make a 'level editor' as a seperate program, so that my non-coding partner can take up some of the level making slack (and possibly for playermade content, if it all goes well).

Please tell me, do I have a hope in hell?

What I have tried/thought about so far...
1)Thought about data statements - ick, no, I want to be able to load each level seperately, and I don't think I can do that with data.
2)Arrays mk1 - I tried one, 3d array in the beginning for just co-ordinates. Far too limiting.
3)Arrays mk2 - I am currently using two arrays; one 3d that lists the coordinates, and another, 2d, that gives the name as a string. However, it's clumsy and I have to declare the arrays first - which I'd rather not do, as the game could end up with a great many levels. Also - I can't load a file from a variable. (Possible?)
4)Thought about memblocks - All very new and scary - I don't know if I can mix variable types, and I don't have the expansion.

Ta.
kevil
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: Netherlands
Posted: 1st Jul 2003 23:07
Could you give me an example of what you want to save. It's not totally clear to me, but I don't think it should be very hard.
Maybe some source to show what you want to do.

Kevil

Tinkergirl
21
Years of Service
User Offline
Joined: 1st Jul 2003
Location: United Kingdom
Posted: 2nd Jul 2003 13:22
Hi, thanks for replying.

I'm afraid as what I currently have in the program is what I'm trying to replace (as it doesn't do the job), what I want to be storing will have to be in pseudocode.
For example - in the file "democity.txt"

5,8,"type_bank","Bank Of Scotland",0,"bankscot.txt","democity.txt"
2,4,"type_hotel","Ritzi",0,"ritzi.txt","democity.txt"
.
.
.
Where the first two numbers are the co-ordinates, the next entry is the type, the next entry is the unique name, after that is the strength, after that it has the name of the smaller 'internal' level within it, and finally it lists the name of the file that it is in. (Whether or not that last is nessesary, I can't tell yet.)

I'd like to be able to save and load the information, much like I'd be able to do with an array, but I'd like the mixed types (if ossible) and the ability to load in the information with a variable name (and not have to dim a silly number of arrays at the start, when only one or two are ever used at once.)
Thanks.

Tinkergirl
21
Years of Service
User Offline
Joined: 1st Jul 2003
Location: United Kingdom
Posted: 2nd Jul 2003 13:31
Oh, I probably should have mentioned that the order is unimportant - I can work around it, and the number of entries per level/city is not static.

Ta.
kevil
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: Netherlands
Posted: 2nd Jul 2003 13:57
Are you doing this is in DBC or DBPro. Because with DBPro you can use types, which will make it easier. That way you can store everything in one array. If you don't have types, then you'll end up using several arrays or you'll have to use the data right away.

Since the number of entries is not static, you should put the number of entries on top of your file.

Then for loading the files with a variable, you should rename your files like this:

level1.txt
level2.txt
level3.txt

If you want to keep that name (like democity), just put it in the file. This also means you can replace the level strings in the data with levelnumbers. So now if you want to load a level, you'll need a variable which has stored the current level and load like this.

level=5

open to read 1,"level"+str$(level)+".txt"
...
..
.

Then the filedata itself. Let's say you don't have types. I think it's easiest if you store all the data in separate strings. That way you can read it(and maybe change it) when you open the file in notepad.
This way you'll get something like this. We call this file "level1.txt".

democity (name)
2 (# of entries)
5
8
"type_bank"
"Bank Of Scotland"
0
2 (level numbers instead of strings)
1 (level numbers instead of strings)
2
4
"type_hotel"
"Ritzi"
0
3 (level numbers instead of strings)
1 (level numbers instead of strings)
(end of file)


now you can read in the file like this.


level=1

open to read 1,"level"+str$(level)+".txt"
read string 1,name$ (read in the name)
read string 1,q$ : entries=val(q$) (read in the entries and convert the string to a number)

Then dim your arrays:

dim coords(entries,1)
dim type$(entries)
dim entryname$(entries)
dim strength(entries)
dim internallevel(entries)
dim level(entries)

And then start to read everything.

entry=0

repeat
entry=entry+1
read string 1,q$ : coords(entry,0)=val(q$)
read string 1,q$ : coords(entry,1)=val(q$)
read string 1,type$(entry)
read string 1,entryname$(entry)
read string 1,q$ : strength(entry)=val(q$)
read string 1,q$ : internallevel(entry)=val(q$)
read string 1,q$ : level(entry)=val(q$)
until file end(1)=1

close file 1


And then you have all the data and you can do with it what you like.

Kevil

Tinkergirl
21
Years of Service
User Offline
Joined: 1st Jul 2003
Location: United Kingdom
Posted: 2nd Jul 2003 16:35
Thankyou thankyou thankyou!
That sounds like a really robust, clean answer to my problem.
I'd been stuck for a month now and the wall was beginning to mould to the shape of my head.

If I was that kind of girl, and this wasn't a forum - I'd hug you!

Thanks again.

Login to post a reply

Server time is: 2024-09-20 13:49:57
Your offset time is: 2024-09-20 13:49:57