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 / Get the name of an array from string???

Author
Message
Maple Engine
16
Years of Service
User Offline
Joined: 26th Jan 2010
Location:
Posted: 6th Apr 2012 02:33
Hello everyone
Just wondering, is it possible to have an array take it's name from a string?
eg.

string$ = "array"
dim string$(10) < that would create an array called "array"


I know it sounds a little stupid and extremely pointless, But there is a reason ^.^ (everything below is kind of irrelevant, but I don't like asking for help without saying what I will use it for )
I'm creating a terrain generator for a project i'm working on, I originally made it to work directly with matrixes, but now I'm editing it to use arrays, so I can save the arrays in files and load them separately to make objects(sing memblocks.) It will(eventualy >.< be a procedural generator, so I'm saving it in "chunks" (64*64 blocks of the terrain). Right, so each chunk needs to be stored on a separate array, but I need to be able to access the data on an array, only knowing the position of the chunk in the entire terrain. For this my Idea was to label the arrays (chunk0000 ect...), but then I realized I could only get data from the arrays using the specific array name, but I need to be able to access it like this: "chunk"+str$(chunk_x)+str$(chunk_y)(x,y)
I'm sorry I can't explain it better than that >.<
anyway, when I realized that wouldn't work, I thought about only having one array (for the chunk that is being generated at that specific time), and whenever I need data from the other arrays load the datafile that it is saved to as a temporary array, like this:
open datafile to read 1,"saves\terrain1\chunk"+str(chunk_x)+str(chunk_y)+".bin"
load array from datafile ......
I got to this point and realized I could not load it to an array called "temp" , because I saved it as an array called "array"

I seriously can't get my head around this one, If anyone knows how to do what I said at the top, or if anyone knnows another way to solve this (without storing all the data as hidden matriexs and storing the matrix numbers in an array ) help would be greatly appreciated

Lewis

At least i try
http://img192.imageshack.us/img192/1571/errormessagepj.png
Lewis999
15
Years of Service
User Offline
Joined: 23rd Oct 2010
Location:
Posted: 6th Apr 2012 02:38
I just realized I was logged into an old account *sigh*
I'll be using this account to reply
Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 6th Apr 2012 03:28
You can load and save arrays with different names, they don't have to match. What you want isn't possible in DBPro because it's a compiled language, but I don't see why you need it?

[b]
Lewis999
15
Years of Service
User Offline
Joined: 23rd Oct 2010
Location:
Posted: 6th Apr 2012 04:32
Quote: "You can load and save arrays with different names, they don't have to match. What you want isn't possible in DBPro because it's a compiled language, but I don't see why you need it?"


Ah, I wrongly assumed that you could save multiple arrays to one file, so when it was loaded you would need to use the same name.
I'll see what I can do with loading the files as I need them, although it's still not the ideal solution. It would be better to keep all the arrays loaded and have a way of referencing them.

As I said before I'm not great at explaining things, so I'm not even going to try explaining exactly why I need this specifically, but It would be useful not to have to rewrite 90% of the code I already have >.<

Anyway, thanks for the help, I'll see what I can do

Lewis
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 6th Apr 2012 04:39
You could just save the array, and the first element of the array is its number. The array would look like this..

0,45,67,78,84

The next arrays would be saved like this...

1,54,78,98,20

2,34,36,56,67

Then by reading the first data element you have some sort of numerical storage system. If that helps.

Lewis999
15
Years of Service
User Offline
Joined: 23rd Oct 2010
Location:
Posted: 6th Apr 2012 06:50
Thanks for the help, That would probably works as well. I've just managed it by loading the arrays I need back from the files only when I need them, so I'm only using 2 arrays at a time. This seems like the fastest way of doing thing for now, It's almost 10x faster than using matrixes at generating a 1024x1024 terrain than using matrixes ^.^

Again, thanks for the help
Mage
Valued Member
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location:
Posted: 6th Apr 2012 22:09
Try adding an extra dimension to the array.

TerrainArray( X, Y, INDEX )

Where INDEX is the arrays designated number. This will allow you to then identify specific 2D arrays by number, stored in a larger 3D array.


Hope this helps.

Login to post a reply

Server time is: 2026-07-10 10:20:39
Your offset time is: 2026-07-10 10:20:39