arg: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
mNo edit summary
m (Text replacement - "<source" to "<syntaxhighlight")
 
(5 intermediate revisions by 3 users not shown)
Line 4: Line 4:
|description=
|description=
Is used to extract arguments that are passed to a macro when called as a user defined function.
Is used to extract arguments that are passed to a macro when called as a user defined function.
User functions are defined with the [[defineFunction|defineFunction()]] function. Once you have defined a function you can
User functions are defined with the [[defineFunction|defineFunction()]] function. Once you have defined a function you can call it as you would call any of the existing functions, for example {{code| attackRoll(Strength, -1)}}. The {{code|arg()}} function is used within the macro that is called to extract each of these arguments. The index of the first argument is 0.
call it as you would call any of the existing functions, for example
{{code| attackRoll(Strength, -1)}}. The {{code|arg()}} function is used within the macro that is called to extract each
of these arguments. The index of the first argument is 0.
 
 
The [[argCount|{{code|argCount()}}]] function is often used in conjunction with {{code|arg()}} to determine the number
of arguments that have been passed to the user defined function.


The [[argCount|{{code|argCount()}}]] function is often used in conjunction with {{code|arg()}} to determine the number of arguments that have been passed to the user defined function.


|usage=
|usage=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
arg(index)
arg(index)
</source>
</syntaxhighlight>
'''Parameters'''
'''Parameters'''
* {{code|index}} - The index of the argument to return. Indexes begin at {{code|0}}.
* {{code|index}} - The index of the argument to return. Indexes begin at {{code|0}}.


|example=
|example=
Given a user defined function called {{code|attackRoll()}} which accepts two arguments, which are attribute value and  
Given a user defined function called {{code|attackRoll()}} which accepts two arguments, which are attribute value and bonus you could call it in the following way.
bonus you could call it in the following way.
<syntaxhighlight lang="mtmacro" line>
<source lang="mtmacro" line>
[attackRoll(12, -1)]
[attackRoll(12, -1)]
</source>
</syntaxhighlight>


Then inside the macro that implements the user defined function you can do the following.
Then inside the macro that implements the user defined function you can do the following.
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h: attr = arg(0)]
[h: attr = arg(0)]
[h: bonus = arg(1)]
[h: bonus = arg(1)]
[r: 1d20 + floor(attr/2) + bonus]
[r: 1d20 + floor(attr/2) + bonus]
</source>
</syntaxhighlight>


|also=
|also=

Latest revision as of 23:59, 14 March 2023

arg() Function

Introduced in version 1.3b51
Is used to extract arguments that are passed to a macro when called as a user defined function.

User functions are defined with the defineFunction() function. Once you have defined a function you can call it as you would call any of the existing functions, for example attackRoll(Strength, -1). The arg() function is used within the macro that is called to extract each of these arguments. The index of the first argument is 0.

The argCount() function is often used in conjunction with arg() to determine the number of arguments that have been passed to the user defined function.

Usage

arg(index)

Parameters

  • index - The index of the argument to return. Indexes begin at 0.

Example

Given a user defined function called attackRoll() which accepts two arguments, which are attribute value and bonus you could call it in the following way.
[attackRoll(12, -1)]

Then inside the macro that implements the user defined function you can do the following.

[h: attr = arg(0)]
[h: bonus = arg(1)]
[r: 1d20 + floor(attr/2) + bonus]

See Also