defineFunction: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
mNo edit summary
(Updated with 1.3b56 changes.)
Line 1: Line 1:
{{stub}}
{{MacroFunction
{{MacroFunction
|name=defineFunction
|name=defineFunction
Line 10: Line 9:
<source lang="mtmacro" line>
<source lang="mtmacro" line>
defineFunction(function, macro)
defineFunction(function, macro)
</source>
<source lang="mtmacro" line>
defineFunction(function, macro, ignoreOutput)
</source>
<source lang="mtmacro" line>
defineFunction(function, macro, ignoreOutput, newScope)
</source>
</source>
'''Parameters'''
'''Parameters'''
* {{code|function}} - The name of the user defined function to be defined.  
{{param|function|The name of the user defined function to be defined. }}
* {{code|macro}} - The name and location of the macro that is called when the user defined function is used.
{{param|macro|The name and location of the macro that is called when the user defined function is used.}}
 
{{param|ignoreOutput|If the defined function should ignore all output and only return the value of {{code|macro.return}}, defaults to {{false}}.}}
 
{{param|newScope|If the defined function should create a new variable scope when executed, defaults to {{true}}. A new variable scope means that the defined function can only read the variables of the macro that called it; if you do not create a new scope the defined function can read, update, and create variables in its parent's variable scope.}}


|examples=
|example=
<source lang="mtmacro" line>
<source lang="mtmacro" line>
[h: defineFunction("character.heal", "heal@Lib:Character")]
[h: defineFunction("character.heal", "heal@Lib:Character")]
</source>
</source>


Defines a function character.heal() which calls heal@Lib:Character when evoked.
Defines a function {{code|character.heal()}} which calls {{code|heal@Lib:Character}} when evoked.
 
|also=
{{func|oldFunction}}
 
|changes=
{{change|1.3b56|Added {{code|ignoreOutput}} and {{code|newScope}} parameter options.}}
}}
}}


[[Category:User Defined Function]]
[[Category:User Defined Function]]

Revision as of 06:20, 22 April 2009

defineFunction() Function

 Note: This function can only be used in a Trusted Macro

Introduced in version 1.3b51
Defines a user function that can be used anywhere that core functions can be used. A user defined function is a link to another macro.

Usage

defineFunction(function, macro)
defineFunction(function, macro, ignoreOutput)
defineFunction(function, macro, ignoreOutput, newScope)

Parameters

  • function - The name of the user defined function to be defined.
  • macro - The name and location of the macro that is called when the user defined function is used.
  • ignoreOutput - If the defined function should ignore all output and only return the value of macro.return, defaults to false(0).
  • newScope - If the defined function should create a new variable scope when executed, defaults to true(1). A new variable scope means that the defined function can only read the variables of the macro that called it; if you do not create a new scope the defined function can read, update, and create variables in its parent's variable scope.

Example

[h: defineFunction("character.heal", "heal@Lib:Character")]
Defines a function character.heal() which calls heal@Lib:Character when evoked.

See Also

Version Changes

  • 1.3b56 - Added ignoreOutput and newScope parameter options.