How do I get the last object in a linked list?
I was hoping Object.GetLastInList would work but it doesnt.
Any ideas?
I was hoping Object.GetLastInList would work but it doesnt.
Any ideas?
mylist:TList=New TList '(fill up list) link:TLink=mylist.FirstLink() While whatever If KeyHit(KEY_UP) 'move to previous item If link.PrevLink() link=link.PrevLink() Else 'this was the first link, so wrap around to the last one in the list link=mylist.LastLink() EndIf ElseIf KeyHit(KEY_DOWN) 'move to next item If link.NextLink() link=link.NextLink() Else 'this is the last link, so wrap around to the first one in the list link=mylist.FirstLink() EndIf EndIf 'do whatever you do with the current link here Wend
Type TBezier Field x1,x2,vx1,vx2,y1,y2,vy1,vy2 Field t:Float Field pointx:Float,pointy:Float Function AddBezier(x1,x2,vx1,vx2,y1,y2,vy1,vy2) Local Bezier:TBezier = New TBezier Bezier.x1=x1 ' *************** But x1 IS DEFINED Bezier.y1=y1 Bezier.x2=x2 Bezier.y2=y2 Bezier.vx1=vx1 Bezier.vx2=vx2 Bezier.vy2=vy2 Bezier.vy1=vy1 BezierList.AddLast(Bezier) End Function Function DrawBeziers() For Local Bezier:TBezier = EachIn BezierList For Bezier.t:Float=0 To 1 Step .005 Bezier.pointx:Float = bezier.x1*(1-bezier.t)^3 + 3*bezier.vx1*(1-bezier.t)^2*bezier.t + 3*bezier.vx2*(1-bezier.t)*bezier.t^2 + bezier.x2*bezier.t^3 Bezier.pointy:Float = bezier.y1*(1-bezier.t)^3 + 3*bezier.vy1*(1-bezier.t)^2*bezier.t + 3*bezier.vy2*(1-bezier.t)*bezier.t^2 + bezier.y2*bezier.t^3 SetColor 180,180,180 Plot bezier.pointx,bezier.pointy Next Next EndFunction Function SubBezier() Local Bezier = BezierList.Last() Print Bezier.x1 ' ******************** <- This will return an error saying x1 is not found BezierList.Remove(Bezier) End Function End Type
Type TBezier Field x1,x2,vx1,vx2,y1,y2,vy1,vy2 Field t:Float Field pointx:Float,pointy:Float Function AddBezier(x1,x2,vx1,vx2,y1,y2,vy1,vy2) Local Bezier:TBezier = New TBezier Bezier.x1=x1 ' *************** But x1 IS DEFINED Bezier.y1=y1 Bezier.x2=x2 Bezier.y2=y2 Bezier.vx1=vx1 Bezier.vx2=vx2 Bezier.vy2=vy2 Bezier.vy1=vy1 BezierList.AddLast(Bezier) End Function Function DrawBeziers() For Local Bezier:TBezier = EachIn BezierList For Bezier.t:Float=0 To 1 Step .005 Bezier.pointx:Float = bezier.x1*(1-bezier.t)^3 + 3*bezier.vx1*(1-bezier.t)^2*bezier.t + 3*bezier.vx2*(1-bezier.t)*bezier.t^2 + bezier.x2*bezier.t^3 Bezier.pointy:Float = bezier.y1*(1-bezier.t)^3 + 3*bezier.vy1*(1-bezier.t)^2*bezier.t + 3*bezier.vy2*(1-bezier.t)*bezier.t^2 + bezier.y2*bezier.t^3 SetColor 180,180,180 Plot bezier.pointx,bezier.pointy Next Next EndFunction Function SubBezier() Local Bezier:TBezier = BezierList.Last() <---- need to define the type Print Bezier.x1 ' ******************** <- This will return an error saying x1 is not found BezierList.Remove(Bezier) End Function End Type