How to pass a default type to a function?
Blitz3D Forums/Blitz3D Programming/How to pass a default type to a function?
| ||
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?! |
| ||
Call the function with null for that parameter. You can not specify null as a default because it is not a constant. |
| ||
(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. |
| ||
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 :/ |