GetLastInList
BlitzMax Forums/BlitzMax Beginners Area/GetLastInList
| ||
How do I get the last object in a linked list? I was hoping Object.GetLastInList would work but it doesnt. Any ideas? |
| ||
The method Last() returns the last Object in a Tlist. Example lastobj:Object=mylist.Last() |
| ||
Thank you very much your post was very helpful and will be applied to my program. However, I have another question. Lets say I made a program that let me go through each type one by one. If I hit the UP ARROW, I would go to the NEXT type, and if I hit the DOWN ARROW, I would go to the PREVIOUS type. Now if I hit the UP ARROW and I was at the last type, then obviously I would want it to go to the FIRST type (from first to last if down arrow hit respectrivly) How do you select each type? All I can see is First, Last, and EachIn() but not a specific number? |
| ||
WARPY from the #blitzbasic IRC responded with a great answer.. We need to add links.. and we're good to go.. 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 |
| ||
Might be too late but does this help... prevlink |
| ||
you mean: www.BlitzMax.com/Community/posts.php?topic=51996&hl=prevlink lol |
| ||
... don't know what you mean :) Anyway, if that's LOL then keep away from the Comedy store. :) |
| ||
LOL All your cookies are belong to blitzmax now. |
| ||
For some reason I cant get any of the field data from the Object when I do it this way. It treats it like the field data does not exist, why? Please pay attention to the code with ***** in front of it 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 |
| ||
Why I can't run the code? Compiler Error Unable to convert from 'Object' to 'TBezier' line: Local Bezier:TBezier = BezierList.Last() |
| ||
If that line is a problem then try this :Local Bezier:TBezier = TBezier(BezierList.Last()) casting from Object (which I assume Last() is returning?) to your TBezier type. |
| ||
Thanks Brucey. |