LoginLogin

Undefined variables

Root / General / [.]

12Me21Created:
When you do something like
LOCATE ,0
the first value isn't a real, an integer, or a string. It's undefined. In most cases, using undefined values causes errors, but you can detect them:
DEF ISUNDEF(VALUE)
 VAR NX=0,NY=0
 VAR ID=SPSET(0,0,0,0,0)
 SPOFS ID,0,1
 SPOFS ID,VALUE,VALUE
 SPOFS ID OUT NX,NY
 SPCLR ID
 RETURN NX==1 && NY==0
END
This allows "optional" arguments in user-defined functions:
DEF EXAMPLE A1,A2
 PRINT A1;" ";
 IF !ISUNDEF(A2) THEN PRINT A2
END
EXAMPLE 1,2 'prints "1 2"
EXAMPLE 3, 'prints "3"
Hopefully there is a more efficient way of detecting undefined variables, so optional arguments are more practical to use.