Blitz3D+ Command Reference

Null

Parameters

None.

Description

The empty object handle - a type variable that points at nothing.

Null is what you get from First or Last on an empty list, from After at the end of a list and Before at the start, and it is the starting value of any object field or variable you have not assigned yet.

You use it for both testing and clearing. If target = Null Then FindNewTarget guards against acting on an object that is not there, and target = Null after the thing dies is how you let go of it. Because Null is zero underneath, If Not target and If target = Null do the same job, and If target on its own is true whenever there is something to work with.

Checking for Null is the standard end condition when stepping through a list by hand with First and After, and the standard emptiness test for a whole type.

It matters most after Delete. Deleting an object does not clear other variables that pointed at it, so setting them to Null yourself - and checking before use - is what keeps a dead enemy from crashing the missile chasing it.

See also: Type, New, Delete, First, After, False.

Example

; Null Example
; ------------

Type Enemy
    Field name$
    Field hp
End Type

; Create the level boss
boss.Enemy=New Enemy
boss\name="Dread King"
boss\hp=200

; Compare a Type variable with Null to see if it points at an object
If boss<>Null Then Print "The "+boss\name+" lives! ("+boss\hp+" hp)"

; The boss is defeated
Delete boss

; After Delete, the variable no longer points at an object - it is Null
If boss=Null Then Print "The boss is gone - the variable is now Null."

Print ""
Print "Press any key to close the example"
WaitKey

End

Index