List Object Problem

BlitzMax Forums/BlitzMax Beginners Area/List Object Problem

Stuart Morgan(Posted 2005) [#1]
Hi

I want to assign a type object to the previous object in the list. In Blitz3D this would have been..
alien = Before alien

I imported this BB code into Max and it told me to use...
alien = alien.Before()

But when I then compile it it says Identifier 'Before' not found. What am I doing wrong and how do I solve this.

Thanks


tonyg(Posted 2005) [#2]
Types don't automatically create a list in Bmx. You have to create your own and then you could use method
InsertBeforeLink.


Perturbatio(Posted 2005) [#3]
Type TAlien
	Global AlienList : TList 'global list to hold the aliens
	Field X:Int
	Field Y:Int

	Function Create:TAlien(Xval: Int, YVal: Int)
		Local tempAlien:TAlien = New TAlien
			If Not AlienList Then AlienList:TList = New TList 'create list if it does not exist
			tempAlien.X = XVal
			tempAlien.Y = YVal
			AlienList.AddLast(tempAlien)
		Return tempAlien
	End Function
End Type

Local a:TAlien

For Local b:Int = 0 To 10
	a:TAlien = TAlien.Create(b,b)
Next

For Local tempAlien:TAlien = EachIn TAlien.AlienList
	Print tempAlien.X + ", " + tempAlien.Y
Next


You can then use the TList functions on TAlien.AlienList




Stuart Morgan(Posted 2005) [#4]
I have my list already. So I would assume it would be something like..
Link = MyList.FindLink(alien)
Link.InsertBeforeLink(alien,MyList.LastLink)
Still says Identifier 'InsertBeforeLink' not found when I try to compile it. Whats going wrong here?


Perturbatio(Posted 2005) [#5]
try:
MyList.InsertBeforeLink(Alien, MyList.LastLink)



tonyg(Posted 2005) [#6]
my_link:TLink = mylist.findlink(mmmmm)
mylist.insertbeforelink(nnnnn,my_link)

I can't be sure of these as I struggle with these methods.
Somebody made a good example post somewhere so search on InsertBeforeLink.


Stuart Morgan(Posted 2005) [#7]
Compile error says "Unable to convert from 'TLink()' to 'TLink'. ???


Perturbatio(Posted 2005) [#8]
TLink() is a function that returns a TLink, TLink is a type

Can you post a little more code? It would make it easier to debug.


tonyg(Posted 2005) [#9]
Does this help...
here


Stuart Morgan(Posted 2005) [#10]
Heres the code.



Actually it is working its just in an infinite loop now I think....


Perturbatio(Posted 2005) [#11]
It doesn't look like you're changing the win value at any point, so this would continue ad infinitum.
	win:Window = Window(WindowList.Last)
	While win <> Null
	    ' Update / draw window
			
	    TmpLink:TLink = WindowList.LastLink()
	    WindowList.InsertBeforeLink(win,TmpLink)
	Wend



Stuart Morgan(Posted 2005) [#12]
All that I want is the BlitzMax equivalent of this Blitz3D code...
win.Window = Last Window
While win <> Null
    win = Before win
Wend



Stuart Morgan(Posted 2005) [#13]
Are the two any different?


Stuart Morgan(Posted 2005) [#14]
Ok I have worked around the problem now with the following code. Its not ideal but It does the same thing. Thanks for all of your help.