Type calling other types methods/functions

BlitzMax Forums/BlitzMax Beginners Area/Type calling other types methods/functions

I have a Create function in one type (TPlayer) that I want to call and have it access a create function in another type (TBall) so I can add it to a list.

I have included an example of it here, which seems to work, but I have a couple of questions

Type Tplayer
	Field x:Int, y:Int
	Field image:TImage
	Field list:Tlist
	

	
	
	
	Method CreateBall()
		Local NewBall:TBall
		NewBall = New TBall
		NewBall = NewBall.Create(2)
		
		NewBall.x=200
		NewBall.y=100
		list.AddLast ( Newball )
	End Method
	
EndType


Type TBall
	Field x:Int, y:Int
	Field image:TImage
	
	Method Create:TBall(colour:Int)
		Local NewBall:TBall
		NewBall = New TBall
		NewBall.ballType=colour
		
		Select (colour)
			Case 1
				NewBall.image=LoadImage("red.png")
			Case 2
				NewBall.image=LoadImage("blue.png")
		End Select

		
		'Additional set up stuff
		Return NewBall
	End Method
	
	
	Method New()
	
		'Should I put setup stuff in here
	EndMethod
	
EndType


1. NewBall = NewBall.Create(2) - just doesnt seem right- creating a local TBall which then calls its method 'Create', which then creates another local TBall, initialises it and returns it doesnt seem nice at all!

2. Most of the OOP code I see has a create function but I'm wondering why if New is always called when new object is created - why cant all the setting up of the object just go into the new Method? Is it because you can only call a method if the object exists otherwise you have to create the object in a function?

I'm basically looking for the cleanest way of doing things.
Thanks

1- I would declare create as a function within TBall. Then its Newball=Tball.create(2).

2. Setup stuff can go in the new method. I don't think you can pass parameters to it though - which is the reason that in this instance you would want to use the method above.

Ok thanks. So where does the new method come from? If you declare your own is that overriding whatever created the default one?

I wouldn't say it overides- it just seems that the new method is automatically called right after object is created by the standard new method. That's what I think, but I'm by no means certain.