AddList / removeList

BlitzMax Forums/BlitzMax Beginners Area/AddList / removeList

Hi. I have an object of type TBall (called PlayerBall) and a list of TBalls (called ballList). What I'd like to do is swap playerBall with the first in the list of ballList. (so playerBall becomes first in the list of BallList and the first object in BallList now becomes PlayerBall).

To copy the first in the list of BallList I have done this:

'Make a copy of playerBall:
Local tempPlayerBall:TBall
tempPlayerBall= playerBall

'Then remove the first item on the list and assign it to player ball
playerBall=TBall(ballList.removefirst())

'And finally add tempPlayerBall (a copy of original playerBall) to the list:
ballList.AddFirst(tempPlayerBall)


I'm getting some strange results and I'm assuming its down to what I'm doing here?
thanks

i didnt think you could do that...
playerBall=TBall(ballList.removefirst())
i dont think it returns an object

...

what you will need todo is
playerball = tball(balllist.first())
balllist.removefirst()

...

of course i coould be wrong and you could just do a null test on playerball

But isnt that just adding playerBall to the first position in the list and then instantly removing it? (as its in first position after adding it)?
EDIT
Crap, of course its not - but its just copying the first in the list to playerBall and then removing it(without adding playerBall to ballList). I guess this would be the solution:

local tempBall:TBall
TempBall = playerBall
playerball = tball(balllist.first())
balllist.removefirst()

ballList.AddFirst ( tempBall )


but it works :D
SeedRnd(MilliSecs())

Type TBall

	Field radius%

End Type

Global playerball:Tball
playerball = New TBall
playerball.radius = Rand(0, 100)
Print playerball.radius

Global balllist:Tlist = CreateList()
For Local i = 0 To 100

	Local aball:Tball = New TBall
	aball.radius = Rand(0, 100)
	balllist.addlast(aball)

Next

myfunc()

Function myfunc()

	Local tmpBall:TBall = playerball
	Print tmpball.radius
	
	Print tball(balllist.first()).radius
	playerball = tball(balllist.first())
	Print playerball.radius + " - V - " + tmpball.radius
	balllist.removefirst()
	Print tball(balllist.first()).radius
	Print playerball.radius + " - V - " + tmpball.radius
	
	balllist.addfirst(tmpball)
	Print tball(balllist.first()).radius

End Function


edit: oh, ok np

thanks for the help!