RETURN

From HEWIKI
Jump to: navigation, search

RETURN [<value>]

Arguments

<value> 
(optional) The data to be returned to the calling script.

Description

Functions may return a single variable to the calling script, although this value may be a complex type, such as a class. This is done by declaring the return type in the function's signature, as shown here:

function ReturnValue() as Integer
  i as Integer = 5
  return i
.

If no return type is included in the signature, then upon a RETURN command, the called function simply returns control to the calling script, without sending any particular data:

function ReturnNoValue()
  return
.

If a function declares that it returns a value but fails to do so, a Script Error is produced at runtime.

Functions can also be used as part of an expression. For example:

  OutputMsg("The number is "+itos(5))
 
  response_s = "Hi "+FindName(friendList,"spouse")+"!"

(Note: This is easier with HSL functions than built-in functions -- some built-in functions cannot yet be embedded)

If a function does not declare a return type, then the RETURN command is not required, and control simply returns to the calling function when it gets to the end of the function.

Example

function DoStuff(wand as noderef, spell as integer) as string
  waveWand(wand)
  return "The wand was waved!  Spell " + spell + " was cast."
.
 
MsgArea(DoStuff(wand,spell))
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox