constructors
BlitzMax Forums/BlitzMax Programming/constructors
| ||
does anyone know how to use constructors in BMax i know how to use New as a method but i want to make multiple ones or pass variables into the method |
| ||
I don't think there are real constructors in bmax. you just add functions like the one below to the type.Function Create:SpriteFrame(frame:Int,nextSpeed:Long,prevSpeed:Long) Local m:SpriteFrame = New SpriteFrame m.frame = frame m.nextSpeed = nextSpeed m.prevSpeed = prevSpeed Return m End Function |
| ||
Well, there is that other method too ;)Type TList Method Create:TList() Return Self EndMethod EndType Local list:TList = New TList.Create() |
| ||
Easiest way for constructor:Type TTest field x:int, y:int Method Create:TTest(x:int, y:int) self.x = x self.y = y return self end method end type global Test:TTest = new TTest.Create(10,10) ' or for making sure you will never have precedence problems: ' global Test:TTest = (new TTest).Create(10,10) |
| ||
You are all nuts using that "New TWhatever.Create()" method instead of the function as Scott Shaver has posted. Uh that's just my 2 cents. Also way to confuse link1426. |
| ||
you can also override the New() method.. |
| ||
@Grable & Dreamora That had never occured to me before. I prefer this form to the Function alternative (which I'de been using previously.) |
| ||
You are all nuts using that "New TWhatever.Create()" method instead of the function as Scott Shaver has posted. Uh that's just my 2 cents. Also way to confuse link1426. I qite agree. A member function create is a lot more sensible than a member method create. AND is has the bonus that the new is inside the function (well can be) BUT my member function Create just calls a member method allocate |
| ||
thank you and i will use th function way instead of a method now i gotta redo some code, what a pain in the arse |