[↑]
SmileBASIC4 Replica Reference
DEF
1. Define a user-defined command with no arguments and no return value

DEF DefinitionName

Example

' Display characters
DEF FUNC
PRINT "SAMPLE" 
END
' Call
FUNC
2. Define a user-defined command with parameters and no return value

DEF DefinitionName Parameter[,Parameter...]

Parameter

If there are parameters that you want to pass to the function, specify the required parameter names separated by commas.

・The parameter name specified here can be used as a variable in DEF-END.

Example

' Display characters at the specified position
DEF FUNC2 X,Y
LOCATE X,Y
PRINT "SAMPLE" 
END
' Call
FUNC2 10,4
3. Define a user-defined function (user-defined command with only one return value)

DEF FunctionName([Parameter[,Parameter...]])

Parameter

If there are parameters that you want to pass to the function, specify the required parameter names separated by commas.

・The parameter name specified here can be used as a variable in DEF-END.

Return Value

When you want a value to return to the caller as a result, specify it as using the RETURN command in DEF-END. (description like RETURN ANS)

Example

'Addition
DEF ADD(X,Y)
RETURN X+Y
END

' Factorial calculation using recursion
DEF FACTORIAL(N)
IF N==1 THEN RETURN N
RETURN N*FACTORIAL(N-1)
END

' String inversion
DEF REVERSE$(T$)
VAR A$="" 'Local string
VAR L=LEN(T$) 'Local
WHILE L>0
 A$=A$+MID$(T$,L-1,1)
 DEC L
WEND
RETURN A$
END

' Call
PRINT ADD(10,5)
PRINT FACTORIAL(4)
PRINT REVERSE$("BASIC")
4. Define a user-defined command with multiple return values

DEF CommandName[Parameter[,Parameter...]] OUT ReturnValue [,ReturnValue...]]

Parameter

If there are parameters that you want to pass to the function, specify the required parameter names separated by commas.

・The parameter name specified here can be used as a variable in DEF-END.

Return Value

Describe as many variable names as you want to return as a result after OUT

・By storing a value to the variable specified here in DEF-END, the value can be returned to the caller.

Example

' Addition and multiplication
DEF CALCPM A,B OUT OP,OM
OP=A+B
OM=A*B
END

' Call
CALCPM 5,10 OUT P,M
PRINT P,M
5. Define a user-defined command with variable-length parameters and variable-length return values

DEF CommandName * [OUT *]

・It is possible to make only the parameter variable-length, or make the return value variable-length.

Parameter

You can declare that the number of parameters is variable-length by writing * (asterisk) after the command name.

・Use DEFARGC, DEFARG, TYPEOF to investigate the number, content, and type of parameters.

Return Value

Write * (asterisk) after OUT to declare that the number of return values is variable-length.

・You can use DEFOUTC and DEFOUT to investigate the number of return values and set the return value.

Example

DEF VARFUNC * OUT *
 FOR I=0 TO DEFOUTC()-1
  DEFOUT I, DEFARG(I)*2
 NEXT
END
About this site
Our site is an unofficial manual site of programming software "SmileBASIC" for NintendoSwitch™.
I acquire the content of the site from the official reference site of the SmileBoom Co.Ltd. that is the development and sales cause of the software in real time (a minimum period of 24 hours update) and display it. For automatic update, contents may become improper.
Please confirm the correct content in an official site.

June 3, 2020
by mim
OK
|