function and methods

BlitzMax Forums/BlitzMax Programming/function and methods

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

I prefer to do it like this (nice because you can also use it again on an object after it has been created):
SuperStrict

Framework brl.blitz

Type TMyType
	
	Field Something:String, SomethingElse:Int
	
		Method Create:TMyType(_Something:String, _SomethingElse:Int)
			
			Something = _Something ' (Or set method)
			SomethingElse = _SomethingElse ' (Or set method)
			
			Return Self
			
		End Method
		
End Type

Local myobject:TMyType

myobject = New TMyType.Create("Hello World!", 7)

' Later on, if needed, instead of setting variables or recreating the object, we can do this
myobject.Create("Goodbye World!", -1)

(essentially the same as Jesse's Init method, but using Create is more descriptive and you do a one line call - since the Create method returns itself)