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
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
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