how to use insertafterlink?

BlitzMax Forums/BlitzMax Beginners Area/how to use insertafterlink?

I tried info I found elsewhere on these forums, noticably a post by dreamora, but the following snippet still doesn't compile:

'create one map entry for the cursor and make cursor handle pointer thing
'maplist.insertafterlink(m)
Local m:map=New map
Local t:tile = tile(tilelist.First())
t.selected=1
m.image=t.image
maplist.addlast(m)
cursor:map=m

Now there's a map entry called cursor which I can access. I'd like to be able to add something after the position cursor is at. I am sorting this list sometimes by Z position (it's a map editor with x,y,z hence the need for the cursor to also reside inside the map data)....

			'if click, add a new map item		
			If mh=1
				Local m:map=New map
				m.x=cursor.x
				m.y=cursor.y
				m.z=cursor.z
				maplist.InsertAfterLink m,maplist.findlink(cursor)
			EndIf


As you can see, I tried the insertafterlink stuff with cursor and a new map entry. It bombs badly.

The error when it crashes is: [ERROR]: Unhandled Exception: Attempt to access field or method of Null object