Type calling other types methods/functions

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

Ant(Posted 2006) [#1]
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


Who was John Galt?(Posted 2006) [#2]
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.


Ant(Posted 2006) [#3]
Ok thanks. So where does the new method come from? If you declare your own is that overriding whatever created the default one?


Who was John Galt?(Posted 2006) [#4]
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.