Force null Type?

Blitz3D Forums/Blitz3D Programming/Force null Type?

Picklesworth(Posted 2005) [#1]
I am trying to make a function that takes a Type instance as an argument, but has it set to default to 0 so that if I want to use all instances of that Type, I can just leave it blank. It's currently crashing when I try:
Function MyFunction(e.entity=False)

How do I do this?


Stevie G(Posted 2005) [#2]
You can't set a default for a type instance like that ( as I discovered too, although = Null is more logical..)

You need to always pass a type instance to the function. Just create a global empty instance .. and pass that. It will always be Null.

This has been discussed in the last few months and as I remember there was also an Object / Handle method of acheiving this.

Stevie


Picklesworth(Posted 2005) [#3]
Yah, there's the Object and Handle way... I think I'll do that.
It's a bit of shame to do so because everything was so uniform...


Storm8191(Posted 2005) [#4]
Yeah, I kinda agree, you outta be able to specify a type as null by default in the function parameters.

On the other hand, you can always check within the function if a given type parameter is null - if need be. When you call the parameter, you can simply pass 'null' to your function, i.e. "DoMyWork red, 117, Null" works just fine. But I still think we need defaults for type instances as function parameters.


Floyd(Posted 2005) [#5]
If you really want to use a null value like this then pass it explicitly: MyFunction( Null ).

It may be slightly less neat than having a Null default value, but that's a minor nuisance.