Qbasicnews.com

Full Version: Maps, and multidimensional arrays.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I'm working on an RPG, and I tried to declare an array with 4 dimensions to store all my maps. The first two would store the world location of the map, and the last two would store the data needed to draw said map. Apparently QBASIC can't do 4D arrays, so I'm stumped as to what to do. Any Ideas?
All of my maps are 31 by 19, and I can't think of any way to have one number reference to a matrix containing map info.

Thanks for the help
What do you mean by the "data needed to draw the map"? What data? Just have your map, and if map(x,y)=1 then put(x*10,y*10),myTile
Perhaps you need to reorganice your data. QB can handle several dimensions, but probably you get out of memory.
Use a 2D array of a user defined type. That way, in each (x, y) cell you can have all the related data.

Code:
TYPE cellType
   tileNo AS INTEGER
   info AS INTEGER
   ...
END TYPE

DIM myMap(19, 31) AS cellType

myMap(7,4).info = 7
...
QB4.5 can handle up to 60 dimensions.
ok, then why won't it let me do 4?
It says
"Subscript out of range" and highlights the DIM statement, which doesn't seem right to me if it can handle 60 dimensions...

Also, what does the TYPE command do exactly in BASIC? Thanks!
Shows us an example fo the code please.
Quote:ok, then why won't it let me do 4?
It says
"Subscript out of range" and highlights the DIM statement, which doesn't seem right to me if it can handle 60 dimensions...

You are running out of static memory. Start QB using QB /AH and add a '$DYNAMIC at the top of your program. If it keeps complaining, reduce the array size.

Quote:Also, what does the TYPE command do exactly in BASIC? Thanks!

Go to QB, enter "TYPE", put the cursor over it and press F1. Magic! Wink
Or go here: http://qbasicnews.com/qboho/qcktype.shtml (same effect) Smile
Ok, the $DYNAMIC say's it's not a statement, so I don't know what's going on there, but anout the F1 thing, I've looked at that, but it doesn't make any sence to me. How can I use one variable to store different variable types within it? I must be missing something obvious, but I sure don't see it.
Quote:Ok, the $DYNAMIC say's it's not a statement, so I don't know what's going on there,

I said '$DYNAMIC (note the ' Wink )

Quote:but anout the F1 thing, I've looked at that, but it doesn't make any sence to me. How can I use one variable to store different variable types within it? I must be missing something obvious, but I sure don't see it.

It creates a structure type. Think about a phone book. You have many entries, every one with NAME, ADDRESS, and PHONE NUMBER. You can create a variable that holds the three values at the same time. You first create a TYPE for that:

Code:
TYPE phoneBookType
   TheName AS STRING * 20
   Address AS STRING * 200
   PhoneNumber AS STRING * 12
END TYPE

Then you declare an array of that type:

Code:
DIM phoneBook(100) AS phoneBookType

You can access every "subsection" using the DOT operand:

Code:
phonebook(7).TheName = "Federico"

or

Code:
PRINT phonebook(10).PhoneNumber

---

You can also create a type to store a coordinate:

Code:
TYPE coordinatesType
   x AS INTEGER
   y AS INTEGER
END TYPE

DIM Dots(1000) AS coordinatesType

Now you can store x, y coordinates in a single array entry:

Code:
Dots(10).x = 100: Dots(10).y = 100
Pages: 1 2