Types as Optional Parameters

Blitz3D Forums/Blitz3D Beginners Area/Types as Optional Parameters

HappyCat(Posted 2004) [#1]
Can you do things like:

Function DoSomething(SomeObject.SomeType = Null)

I'm assuming not as I can't get it to work.


semar(Posted 2004) [#2]
.


soja(Posted 2004) [#3]
I don't think so.


Tiger(Posted 2004) [#4]
Its not possible with blitz.


N(Posted 2004) [#5]
Null is not a constant value, so no,it's impossible.


morduun(Posted 2004) [#6]
Not possible.

Type myType
	Field blah
End Type

Function myFunction(myInstance.myType = Null)
	Return myInstance\blah
End Function

returns an error.

You'd think a fellow who's done more with Blitz3D in the last year than most people have ever done would know something like that, eh? >:D

[EDIT] ROFL: nice edit Noel. Undoubtedly revisionist history accounts for some of that expertise of yours eh? XD[/EDIT]


767pilot(Posted 2004) [#7]
yeah, even I knew that.

but then again maybe im just lying!! :)


N(Posted 2004) [#8]
It's interesting considering it didn't work for me in the past. I shall have to try this again.


DJWoodgate(Posted 2004) [#9]
I suppose you could use the handle and object method. Probably not like this, but it's just an example.

Type myType
	Field blah
End Type

Instance.mytype = myfunction(10)

Print Instance\blah

myfunction(20,Handle(Instance))

Print Instance\blah


WaitKey()

Function myFunction.mytype(value,typehandle=0)
	Local thisinstance.mytype = Object.mytype(typehandle)
	If thisinstance<>Null 
		thisinstance\blah = value
	Else 
		thisinstance = New mytype
		thisinstance\blah = value
	EndIf
	Return thisinstance
End Function



sswift(Posted 2004) [#10]
Someone once tried to explain to me why this is impossible, but I didn't understand what they were trying to say. It seems trivial to me.


HappyCat(Posted 2004) [#11]
Yeah, I find it a bit of a strange omission - I'm sure there must be a good reason.

Never mind, I'll just have to get used to passing in "Null"s instead :-)


Tibit(Posted 2004) [#12]
Function DoSomething(SomeObject.SomeType = Null)

Well this is possible like DJWoodGate said. You can't write it that way, but you can have the same "functionality". But I might have gotten you wrong, Test this sample.

[code]
Function DrawEntry(Pointer%=0)

Local P.SomeType = Object.SomeType Pointer

If P <> Null;Did they send a long an object or just a ZERO?
;Good
Text P\x,P\y,"- Object Verified -"
Else
Text 0,Rand(100),"- Object NOT Verified - or none Found"
End If


End Function


Type SomeType
Field X,Y
End Type

P.SomeType = New SomeType
P\X = 21:P\Y = 50
P2.SomeType = New SomeType
P2\X = 75:P2\Y = 20


DrawEntry(Handle P)
DrawEntry(Handle P2)
DrawEntry(0)
WaitKey()
[code/]