Board Thread:Questions and Answers/@comment-178.200.16.31-20140515180236/@comment-9531161-20140518221321

An array which can hold 16X16 map information can be set like this:

DIM MYMAP(16,16)

Just remember that you HAVE to put CLEAR at the top of your program, because BASIC doesn't like it when you re-define (re-dimension) arrays. So what you want at the top of your program is something like:

ACLS             <- Clears the screen CLEAR            <- Clears the variables DIM MYMAP(16,16) <- Makes an empty space for the map

This map has nothing in it, so you'll have to put map data into it somehow. The map information will be stored as numbers, and each number can represent a different object in your world. For instance, 1 can be grass, 2 can be water, etc. Putting these numbers into the array is up to you, but I'd look around at how other people do it.

If you're storing the map for later use (like a save file), you'll either want to keep the map numbers under 256 or perform some math tricks in order to store larger values. This is because a GRP and MEM file can only store numbers from 0 to 255. The command for storing values into a GRP is GPSET, and the command for reading values (like loading a file) is GSPOIT. You'll want to load the GRP, then read the values one by one. This is done with nested FOR loops (FOR loops inside each other):

GCLS                    <- Clear the GRP save area FOR X=0 TO 15 FOR Y=0 TO 15 GPSET X,Y,MYMAP(X,Y)  <- Save each map location into a unique GRP location NEXT NEXT SAVE "GRP:MYSAVE"       <- Save the values

To load:

LOAD "GRP:MYSAVE"         <- Load the GRP save file FOR X=0 TO 15 FOR Y=0 TO 15 MYMAP(X,Y)=GSPOIT(X,Y)  <- Get the map value from the GRP NEXT NEXT GCLS                      <- Clear off the GRP for later use.