I am doing work on OpenGL collision detection and have a need for an optional method parameter equal to nil. Below is a simplified version of what I would like to code:
In a pushbutton action event
MyCoordinate(3,4,5)
Sub MyCoordinate(x as double, y as double, z as double, x1 as double, y1 as double, z1 as double, optional distance as double = nil)
If distance = nil then
//Do other math
End If
End Sub
The IDE provides two errors:
Parameter “distance” expects type Double, but this is type Nil. MyCoordinate(3,4,5)
Type mismatch error. A double parameter can’t have a Nil default value.
The value that the optional distance variable has at runtime is 0.00000. A distance of 0.00000 is a valid number. Is there another way or a workaround to enable a nil value? I could add another parameter that would be a boolean flag value, and was hoping that someone had a nicer workaround for an optional nil value.
Sub MyCoordinate(x as double, y as double, z as double, x1 as double, y1 as double, z1 as double )
// do math that excludes distance
End Sub
Sub MyCoordinate(x as double, y as double, z as double, x1 as double, y1 as double, z1 as double, distance as double )
// do math that includes distance
End Sub
[quote=486115:@Djamel AIT AMRANE]question about optional, this func. take a default value “eps” if missing.
xojo has not IsMissing [/quote]
The documentation for the Optional keyword has a ton of info you might be looking for http://documentation.xojo.com/api/language/optional.html