Can you pass variables to Method New() ?

BlitzMax Forums/BlitzMax Programming/Can you pass variables to Method New() ?

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.

The use of any Create/DeSerialize feature as a method is useful for coding purposes (less code when using instance creators as a method).

ie, instead of having to create a new object and refer to its fields and methods through the object you can access them directly, especially with less code:
SuperStrict

Framework brl.standardio

Type TMyType
	
	Field MyField:Int
	
	'Less code required
	Method Create:TMyType(_MyField:Int)
		
		MyField = _MyField
		SomeMethod()
		
		Return(Self)
		
	End Method
	
	Method SomeMethod()
		
		Print("Some method... " + MyField)
		
	End Method
	
	'Extra code required
	Function CreateMyType:TMyType(_MyField:Int)
	  Local mytype:TMyType
		mytype = New(TMyType)
		
		mytype.MyField = _MyField
		mytype.SomeMethod()
		
		Return(mytype)
		
	End Function
	
End Type


Local tmp:TMyType

tmp = New(TMyType).Create(100)

tmp = TMyType.CreateMyType(200)


P.S. The last code you posted is invalid, you are attempting to access the field 'kind' from a function in a type (you can only do that with an instance of a type).