I'm sorry my advice was unclear.
You seem to use BG layer #3 only. In this case, you don't need line 1,3,4,7,8 nor 9.
And you should write "64,64" instead of "30,20" in line 2.
Yes. Before you load map data which has been made and saved with smile tool into a BG layer, you have to redefine the size of the layer larger than or equal to 64*64 with "BGSCREEN N,64,64" (N is BG layer number you've chosen), because default size of each BG layer is 25*15.
You should save map data with "SCSAVE" button instead of "SAVE" button in map editor of smile tool. Four map files (SC_xxx_L0 to SC_xxx_L3) will be yielded, and you write one of them as an argument of LOAD in line 5.
What line have an out of range error occured?
I point out a couple of suspicious points in your program as follows.
1) The array name applied in line 5 (LOAD) and line 7 (BGLOAD) are unmatch.
2) You have not defined BG layer #3 as 64*64 map yet.
I overlooked suspicious points.
Could you replace
X2=X2+(X2-X)/D:Y2=Y2+(Y2-Y)/D
with
X2=X2+(X-X2)/D:Y2=Y2+(Y-Y2)/D
?
An enemy will LEAVE a player with the former code.
Write as follows in order to kill divide by zero error.
D=SQR(POW(X2-X,2)+POW(Y2-Y,2))
IF D>0 THEN X2=X2+(X2-X)/D:Y2=Y2-(Y2-Y)/D
The following code is another solution.
D=SQR(POW(X2-X,2)+POW(Y2-Y,2))
IF D>0 THEN
A=ATAN(Y-Y2,X-X2)
X2=X2+COS(A):Y2=Y2+SIN(A)
ENDIF
I guess that the purpose of this code is an enemy's constant speed approach to a player.
The denominator of this code stands for the distance between a player and an enemy. When divide by zero error occurs, an enemy has already collided with a player.