OK, here is a revamp of your project:
Rem Project: DarkDragon Mapper
Rem Created: 6/21/2011 11:32:41 PM
Rem ***** Main Source File *****
Rem Credit to TheComet for his examples......
Rem Notes----
Remstart
Have a collision Tool, where you can set the collision flag on a certain tile,
This will allow multiple layers to have collision.....while in that tool collision = 1 tiles
should be overlayed with like a red tile or something to show it. Just a thought.
Remend
Rem Notes----
Rem Normal Start of Program stuff.
Sync on
Sync Rate 60
backdrop on
color backdrop 0
show mouse
Rem Define Tile Array and type.
type TileType
x as integer : rem x position of tile
y as integer : rem y position of tile
Tilesize as integer : Rem Size of Tile.
index as word : rem what tile is it? This will be the index of the tile(image number, )
grip# as float : rem a value between 0 and 1 defining how well players grip to it. 1=full grip, 0=no grip (they will slip). lol for the rhymes
speed# as float : rem a value between 0 and 1 defining how fast the player can move on this tile. 0=no movement, 1=full movement
collision as boolean : rem 1=collision, 0=no collision DD- May or may not be needed, im adding layers and will have a collision layer
forcex# as float : rem what if you have moving water? This defines how fast the player will be forced on the x axis
forcey# as float : rem same for y axis (Could be >>> Tiles or -> Tiles....)
endtype
rem the array to store all of the tiles in
Global Layers=4 : rem Number of layers(5)
Rem Drawn in reverse order.
Rem 1) Collision 2)Overlay tiles 3)
Global TilesX=63 : rem width of map (64)
Global TilesY=63 : rem height of map (64)
Dim Tile(Layers,TilesX,TilesY) as TileType
Rem For Editor; CurrentScroll Data
Global CurrentTileScrollX
Global CurrentTileScrollY
CurrentTileScrollX = 0
CurrentTileScrollY = 0
rem Set Tiles to default
Rem Code Could be used to clear Map in editor....
for lay = 0 to Layers
for x=0 to TilesX
for y=0 to TilesY
Tile(lay,x,y).index=0 : rem default tile is air
Tile(lay,x,y).Tilesize = 32 : Rem Default size is 32.
next y
next x
next lay
rem make a grid for background
Rem DD- Needs to be 10x10, to fit in bottom right corner.
tilewidth=32
tileheight=32
rem create bitmap for drawing grid on
create bitmap 1,(TilesX+1)*tilewidth,(TilesY+1)*tileheight
ink 0,0
box 0,0,(TilesX+1)*tilewidth-1,(TilesY+1)*tileheight-1 : rem make background black
ink 0xFFFFFFFF,0
for x=0 to TilesX
line x*tilewidth,0,x*tilewidth,TilesY*tileheight
next x
for y=0 to TilesY
line 0,y*tileheight,TilesX*tilewidth,y*tileheight
next y
get image 1000,0,0,(TilesX+1)*tilewidth,(TilesY+1)*tileheight
delete bitmap 1
Rem Heres where we will load in the tilesets, cut them up, and index them by number to be used to render and store in an array.
Rem Tileset array...
Dim TileSet(1000)
Rem Load in tileset....
Load image "TileA2.Png",5000,1
Rem Determine number of tiles to cut......
CutTilesx = int( Image Width(5000)/32 )
CutTilesy = int( Image Height(5000)/32 )
NumberofTilestocut = CutTilesx * CutTilesy
imgindex = 15000
rem Grab to a set aside area of image index...
rem 15000 will be used for air, so images actually start at 15001
paste image 5000,0,0,1
For x = 0 to CutTilesx-1
for y = 0 to CutTilesy-1
inc imgindex
get image imgindex,x*32,y*32,(x*32) + 32,(y*32) + 32,1
next y
next x
Tile(0,0,0).index = 15000
Global CurrentTile as integer = 15001
Global CurrentLayer as integer = 0
state=0
Rem The Main Loop!
Do
rem --------------------------------------
rem Control here, no pasting or rendering
rem --------------------------------------
rem reset cursor
set cursor 0,0
rem editing mode
if state=0
Rem Recive input from user......
mx = int(( Mousex() - CurrentTileScrollX ) / 32 )
my = int(( Mousey() - CurrentTileScrollY ) / 32 )
rem control scrolling of the map with mouse
if mousey()<20 then inc CurrentTileScrollY,(20-mousey())
if mousey()>screen height()-20 then dec CurrentTileScrollY,(mousey()-(screen height()-20))
if mousex()<20 then inc CurrentTileScrollX,(20-mousex())
if mousex()>screen width()-20 then dec CurrentTileScrollX,(mousex()-(screen width()-20))
rem scroll boundaries
if CurrentTileScrollX > 0 then CurrentTileScrollX = 0
if CurrentTileScrollY > 0 then CurrentTileScrollY = 0
if CurrentTileScrollX < (0-(TilesX*tilewidth))+screen width()-1 then CurrentTileScrollX = (0-(TilesX*tilewidth))+screen width()-1
if CurrentTileScrollY < (0-(TilesY*tileheight))+screen height()-1 then CurrentTileScrollY = (0-(TilesY*tileheight))+screen height()-1
rem place tiles with left mouseclick
if mouseclick()=1 then Tile(CurrentLayer,mx,my).index=CurrentTile
rem remove tiles with right mouseclick
if mouseclick()=2 then Tile(CurrentLayer,mx,my).index=15000
rem select a tile by holding spacekey
if spacekey()=1 then state=1
endif
rem select tile mode
if state=1
Rem Recive input from user......
mx = int( Mousex() / 32 )
my = int( Mousey() / 32 )
rem select tile
CurrentTile=mx*CutTilesy+my+15001
rem go back to editing mode
if spacekey()=0 then state=0
endif
rem ---------------------------------------
rem pasting and rendering comes here
rem ---------------------------------------
rem print grid to screen (should be done first)
paste image 1000,CurrentTileScrollX,CurrentTileScrollY
rem draw all tiles (should be done after grid, because the tiles are over the grid)
for lay = 0 to Layers
for x = 0 to TilesX
for y = 0 to TilesY
if Tile(lay,x,y).index > 15000 then paste image Tile(lay,x,y).index,x*Tile(lay,x,y).Tilesize+CurrentTileScrollX,y*Tile(lay,x,y).Tilesize+CurrentTileScrollY,1
next y
next x
next lay
rem display tile image
if state=1
paste image 5000,0,0
endif
rem draw current tileset selected
x=mx+( CurrentTileScrollX / 32 )
y=my+( CurrentTileScrollY / 32 )
sprite 1,x*32-Cwrap(0-CurrentTileScrollX,32),y*32-Cwrap(0-CurrentTileScrollY,32),CurrentTile
set sprite alpha 1,128
rem draw transparent box over current tile
box sprite x(1),sprite y(1),sprite x(1)+32,sprite y(1)+32,0x70FFFFFF
rem print title (should be done last, because it's over everything else)
ink RGB(10,255,50),0
Center Text Screen Width()/2, 15,"--DarkDragon Tile Map Editor--"
ink RGB(100,125,250),0
for w = 1 to 7
Center Text Screen Width()/2, 20+w,"~---------------------------------~"
next w
rem debug info
Print mx
Print my
print CurrentTile
print Cwrap(0-CurrentTileScrollX,32)
print Cwrap(0-CurrentTileScrollY,32)
rem refresh screen
sync
rem end of main loop
Loop
rem end
End
Rem GOSUBS=============================
REM Save Map Routine.....
_Map_save:
if savebutton=1
rem open map
if file exist("map.omg")= 1 then delete file "map.omg"
open to write 1,"map.omg"
rem write data
for lay = 0 to Layers
for x=0 to TilesX
for y=0 to TilesY
write word 1,Tile(lay,x,y).index
write word 1,Tile(lay,x,y).Tilesize
write float 1,Tile(lay,x,y).grip#
write float 1,Tile(lay,x,y).speed#
write byte 1,Tile(lay,x,y).collision
write float 1,Tile(lay,x,y).forcex#
write float 1,Tile(lay,x,y).forcey#
next y
next x
next lay
close file 1
rem wait till nonpress
repeat:until savebutton=0
endif
Rem GOSUBS=============================
rem FUNCTIONS==========================
rem wrap function
function Cwrap(w as integer,t as integer)
while w>t
dec w,t
endwhile
endfunction w
Move the mouse to the edges of the screen to scroll around, left click places a block, right click removes a block, holding space lets you choose a block.
You need to try and keep a good structure in your code, the version you gave me was a little bit messy (please no offense

). If you keep a good and clear structure, you will be able to get much further with programming. I'm not saying I'm the gold standard though, just find a way to keep yourself organized
If you have any questions, I'll be happy to help you out
TheComet