beautypg.com

BrightSign BrightScript 2 Reference Guide User Manual

Page 31

background image

31

Dynamic


In addition to the above types, the return type can be:

Void


Parameters can have default values and expressions.

For example:

Function cat(a, b)

Return a+b „a, b could be numbers or strings

End Function

Function five() As Integer
Return 5
End function


Function add(a As Integer, b As Integer) As Integer
Return a+b
End function

Function add2(a As Integer, b=5 as Integer) As Integer

Return a+b

End Function

Function add3(a As Integer, b=a+5 as Integer) As Integer

Return a+b

End Function


Functions have their own scope.

The statement “Sub” can be used instead of “function” as a shortcut to a function of Void
return Type.

If a function is called from an associative array, then a local variable “m” is set to the
AssociatiaveArray that the function is stored in.

For example:

sub main()
obj={
add: add
a: 5
b: 10
}

obj.add()
print obj.result
end sub

function add() As void