x=New x error

BlitzMax Forums/BlitzMax Programming/x=New x error

As I said,

New, when passed an object instead of a type name, will create a new object of the same type as that object


It's a documentation issue.


The feature is so you can do something like this - which *doesn't* work, because SizeOf is incorrectly returning 0:

Type CloneableObject
	
	Method Clone:Object( )
	
		Local sel:Object = Self
		Local obj:Object = New sel
				
		MemCopy( Byte Ptr( Varptr( obj ) ), Byte Ptr( Varptr( sel ) ), SizeOf( sel ) )

		Return obj
	
	End Method
	
End Type

Type Enemy Extends CloneableObject

	Field x#, y#

End Type

Local BadGuy:Enemy = New Enemy
BadGuy.x = 50
BadGuy.y = 60

Local AnotherBadGuy:Enemy = Enemy( BadGuy.Clone( ) )

RuntimeError AnotherBadGuy.x + "," + AnotherBadGuy.y