Types - InsertAfter ?
BlitzMax Forums/BlitzMax Beginners Area/Types - InsertAfter ?
| ||
How do I mimic the InsertAfer (and InsertBefore for that matter) with the BlitzMax TList system? Here I'm trying to get Mark to sit between Amanda and Mary but he's playing hard to get .... global list:TList=CreateList() Type nametype Field name$ End type Local n:nametype ' build a list of 4 names n=New nametype n.name="Tom" ListAddLast list,n n=New nametype n.name="Amanda" ListAddLast list,n n=New nametype n.name="Mary" ListAddLast list,n n=New nametype n.name="Peter" ListAddLast list,n ShowList Print "Tom, please leave the Big Brother house!" list.RemoveFirst ShowList n=New nametype n.name="Mark" Print "Inserting Mark between Amanda & Mary (lucky guy)" '' list.InsertAfterLink ??? 'ShowList Input "Done. Return to end ..." Function ShowList() Print "(press return ...)" Print " " Input For Local n:nametype=EachIn list Print " -> "+n.name Next Print " " End Function |
| ||
list.InsertAfterLink n, list.findlink( "Amanda" ) |
| ||
isn't possible straight this way. you need to know the object reference of amanda to do this: list.insertafterlink n, list.findlink( ref_to_amanda ) |
| ||
Thanks. Got it working ...Global list:TList=CreateList() Type nametype Field name$ End Type Local n:nametype ' build a list of 4 names n=New nametype n.name="Tom" ListAddLast list,n n=New nametype n.name="Amanda" ListAddLast list,n n=New nametype n.name="Mary" ListAddLast list,n n=New nametype n.name="Peter" ListAddLast list,n ShowList Print "Tom, please leave the Big Brother house!" list.RemoveFirst ShowList Print "Inserting Mark between Amanda & Mary (lucky guy)" For i:nametype=EachIn list If i.name="Amanda" n=New nametype n.name="Mark" list.insertafterlink n, list.findlink(i) EndIf Next ShowList Print "Mary gets upset and walks away .." For n=EachIn list If n.name="Mary" ListRemove list,n EndIf Next ShowList Input "Done. Return to end ..." Function ShowList() Print "(press return ...)" Print " " Input For Local n:nametype=EachIn list Print " -> "+n.name Next Print " " End Function |
| ||
here are some additional list methods' LIST METHODS strict global n$ global list$ global mylist:Tlist Global this_func = 1 Global link_count Global this_link:Tlink Global total_funcs = 5 global listfunction$ Local timer Const WAIT_TIME = 25 Global GH = 640 ; Global GW = 480 ; Global GD = 0 Graphics( GH,GH,GD ) GLobal a$[] = ["one","two","three","four"] mylist:Tlist = ListFromArray(a$) For n$ = EachIn mylist list$ = list$ + n$ + " " Next listfunction$ = "ListFromArray" Repeat cls timer:-1 If timer < 0 Then timer = 0 If Mousedown(1) And timer = 0 changefunction() timer = WAIT_TIME endif SetScale 1,1 SetColor 255,255,255 DrawText "Click Mouse",MouseX(),MouseY()-48 SetColor 255,255,255 DrawText this_func,MouseX(),MouseY()-32 SetColor 255,255,0 DrawText listfunction$,MouseX(),MouseY()-16 SetScale 1.5,1.5 SetColor 255,0,0 DrawText list$,MouseX(),MouseY() flip Until KeyHit(KEY_ESCAPE) Function changefunction() this_func:+1 If this_func > total_funcs Then this_func = 1 Select this_func Case 1 mylist:Tlist = ListFromArray(a$) listfunction$ = "Mylst.ListFromArray(Array)" Case 2 this_link:Tlink = ListFindLink(mylist,"three") mylist.insertbeforelink("2-1/2",this_link) listfunction$ = "Mylist.InsertBeforeLink(object,link--'three')" Case 3 this_link:Tlink = ListFindLink(mylist,"three") mylist.insertafterlink("3-1/2",this_link) listfunction$ = "Mylist.InsertBeforeLink(object,link--'three')" Case 4 mylist:Tlist = ListFromArray(a$) listfunction$ = "Mylist.ListFromArray(Array)" mylist.remove("three") listfunction$ = "remove('three')" Case 5 mylist:Tlist = ListFromArray(a$) link_count = mylist.count() listfunction$ = "Mylist.count() = "+link_count End Select list$ = "" For n$ = EachIn mylist list$ = list$ + n$ + " " Next End Function |