How to pass a default type to a function?

Blitz3D Forums/Blitz3D Programming/How to pass a default type to a function?

Damien Sturdy(Posted 2005) [#1]
hey peeps... Questions in the topic title :)

I need to set a function so calling it without the "gadget" param makes it default to desktop. At the moment i keep getting "error:type".

Code:


Function drawrect(x,y,Lgth,height,fill=0,gadget.ui_gadget=null)
If gadget=Null Then gadget=ui_desktop
 Local bf=GraphicsBuffer()

If gadget\texture<>0 Then
	SetBuffer TextureBuffer(gadget\Texture)
	Rect x,y,lgth,height
	SetBuffer bf
EndIf

End Function



How do i do it?!


DJWoodgate(Posted 2005) [#2]
Call the function with null for that parameter. You can not specify null as a default because it is not a constant.


fall_x(Posted 2005) [#3]
(edit : apparantly DJWoordGate beat me to it ;))
As I understand it, you can't set a default parameter to null, I've had problems with this as well. Actually, I think you can't set a default parameter to any type instance, it has to be a constant value :S
So you could use strings or numbers instead, and then let the function get the right instance if this string is not empty (or the number is not 0), but that would slow it down a bit.


Damien Sturdy(Posted 2005) [#4]
oh bullox. Well, its easier to just have to call with the parameter than have a for/next loop in each function or a function to sort it all... damn.

cheers dudes :/