So, if you do as Hungry Horace suggests you'll save memory also because your "array" elements can be less than 4 bytes. You might have something that looks like:
Rem Calculate the array size
MAP_SIZE=MAP_WIDTH*MAP_HEIGHT
' Allocate Layer0 array
Reserve As Work 10,MAP_SIZE
LAYER0_BASE = Start(10)
' Allocate Layer1 array
Reserve As Work 11,MAP_SIZE
LAYER1_BASE = Start(11)
' Allocate Layer2 array
Reserve As Work 12,MAP_SIZE
LAYER2_BASE = Start(12)
These "arrays" are byte sized, so each element can store values between 0 and 255, so you can encode up to 256 different elements traps, keys, objects, quests, etc.) in each array. If you need more values, you can make each two bytes in size, but here I show the one byte version.
You can write procedures or subroutines to get and set data in the memory bank much like you use an array:
Procedure GET_LAYER0[X,Y]
Shared LAYER0_BASE,MAP_WIDTH,MAP_HEIGHT
' Check that we are within the array bounds
If X<0 Or X>MAP_WIDTH Or Y<0 Or Y>MAP_HEIGHT
RESULT=-1
Pop Proc
EndIf
' Compute the memory address of the X,Y location
ADDRESS=LAYER0_BASE+Y*MAP_WIDTH+X
RESULT=Peek(ADDRESS)
End Proc[RESULT]
Procedure SET_LAYER0[X,Y,VALUE]
Shared LAYER0_BASE,MAP_WIDTH,MAP_HEIGHT
' Check that we are within the array bounds
If X<0 Or X>MAP_WIDTH Or Y<0 Or Y>MAP_HEIGHT
RESULT=-1
Pop Proc
Else
RESULT=0
EndIf
' Compute the memory address of the X,Y location
ADDRESS=LAYER0_BASE+Y*MAP_WIDTH+X
Poke(ADDRESS,VALUE)
End Proc[RESULT]
You can use these like:
' Set 10,20 to a value of 34
SET_LAYER0[10,20,34]
' Get the value of 10,20
GET_LAYER0[10,20]
' After the procedure, the value is stored in a system variable called Param.
VALUE=Param
If you do things this way, you'll save a huge amount of memory (3 MB vs 12 MB for your 3 layers) and you can also use the Save and Load commands to save your layer data to disk and reload it next time. No is need for a secondary file for this purpose.