Default args in functions

Blitz3D Forums/Blitz3D Programming/Default args in functions

QuickSilva(Posted 2003) [#1]
Hello,

Can anyone help with this small problem?

Say I wanted to make a function that has optional arguments that can be passed to it such as a CreateWindow()

function that, at its most basic, only needs to have an xpos,ypos and size passed to it for it to work but for

more power users there are arguments for colour,style etc... so in other words,

CreateWindow(XPos,YPos,Size,[Colour],[Style],[Etc...]) as it would be shown in Blitz help docs.

How can I implement this? If the user misses out the later half of the args, (colour,stlye etc...) then the

function will fail as its missing the correct number of args so I need to fill these with default values if

the user goes with the simple version of the CreateWindow() function.

Is there a clean and easy way to do this?

Jason.


poopla(Posted 2003) [#2]
Function CreateWindow(XPos,YPos,Size,Colour = 0,Style = 0, [etc...])


The parameters like Colour = 0 will always pass the default value if no value is passed when the function is called.


DH(Posted 2003) [#3]
Only issues is that the Value for those arguments has to be a constant (not a variable).