table: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
m (Added a fourth example)
m (Conversion script moved page Table to table: Converting page titles to lowercase)
 
(18 intermediate revisions by 5 users not shown)
Line 3: Line 3:
|version=1.3b39
|version=1.3b39
|description=
|description=
Gets the text value from the specified [[Tables|table]]. If the row is not specified then the default [[Roll|roll]] for the [[Tables|table]] is used. The row can be either a constant or a [[Roll|roll]].
Gets the text value from the specified {{code|table}}. If the row is not specified then the default {{code|roll}} for the {{code|table}} is used. The row can be either a constant or a {{code|roll}}.
 
Note that what this function returns is interpreted as either a string or a number. You can put code in a table entry but that too will be returned as a string and will not be evaluated. To evaluate the result you can use {{func|eval}} to evaluate e.g. the table entry {{code|1d5}} and {{func|evalMacro}} to evaluate e.g. the table entry {{code|[r:1d5]}}


|usage=
|usage=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
table(name)
table(name)
</source>
<source lang="mtmacro" line>
table(name, row)
table(name, row)
</source>
<source lang="mtmacro" line>
tbl(name)
tbl(name)
</source>
<source lang="mtmacro" line>
tbl(name, row)
tbl(name, row)
</source>
</syntaxhighlight>
'''Parameters'''
'''Parameters'''
* {{code|name}} - A string containing the name of the [[Table|table]].
* {{code|name}} - A string containing the name of the [[Table|table]].
Line 24: Line 20:
|examples=
|examples=
'''Example 1:''' Display a random value from table {{code|"tbl1"}} using default roll:
'''Example 1:''' Display a random value from table {{code|"tbl1"}} using default roll:
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[r: table("tbl1")]
[r: table("tbl1")]
</source>
</syntaxhighlight>


'''Example 2:''' Display the first value from table {{code|"tbl1"}}:
'''Example 2:''' Display the first value from table {{code|"tbl1"}}:
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[r: table("tbl1", 1)]
[r: table("tbl1", 1)]
</source>
</syntaxhighlight>


'''Example 3:''' Display one of the first four values from {{code|"tbl1"}}, chosen randomly:
'''Example 3:''' Display one of the first four values from {{code|"tbl1"}}, chosen randomly:
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[r: table("tbl1", "1d4")]
[r: table("tbl1", "1d4")]
</source>
</syntaxhighlight>


'''Example 4:''' Display a table row that corresponds to a token property's value (the value must be numeric):
'''Example 4:''' Display a table row that corresponds to a token property's value (the value must be numeric):
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[r: table("tbl1", Intelligence)]
[r: table("tbl1", Intelligence)]
[r: table("tbl1", getProperty("PCLevel"))]
[r: table("tbl1", getProperty("PCLevel"))]
</source>
</syntaxhighlight>
 
'''Example 5:''' Evaluate the outcome of a table entry. The table entry '''must''' thus be something that can be evaluated, like {{code|1d10}} or {{code|roll(1,6)}} or {{code|3+5}}:
<syntaxhighlight lang="mtmacro" line>
[r: eval(table("tbl1"))]
</syntaxhighlight>
 
'''Example 5:''' Evaluate the outcome of a table entry that contains code. The table entry '''can''' thus contain code, but its not required. 'code' in this case is anything between [brackets]. An example table entry could be ''[h:roll=1d20]You [r:if(roll<10, 'hit', 'miss')] your target.'' :
<syntaxhighlight lang="mtmacro" line>
[r: evalMacro(table("tbl1"))]
</syntaxhighlight>


|also=
|also=
[[Tables]], [[tableImage|tableImage()]]
{{func|tableImage}}
 
<br>There is a tool available to import tables from excel. You can find more about this [http://forums.rptools.net/viewtopic.php?f=3&t=11568#p124557 here]
 
}}
}}
[[Category:Table Function]]
[[Category:Table Function]]

Latest revision as of 23:59, 9 February 2023

table() Function

Introduced in version 1.3b39
Gets the text value from the specified table. If the row is not specified then the default roll for the table is used. The row can be either a constant or a roll. Note that what this function returns is interpreted as either a string or a number. You can put code in a table entry but that too will be returned as a string and will not be evaluated. To evaluate the result you can use eval() to evaluate e.g. the table entry 1d5 and evalMacro() to evaluate e.g. the table entry [r:1d5]

Usage

table(name)
table(name, row)
tbl(name)
tbl(name, row)

Parameters

  • name - A string containing the name of the table.
  • row - The row of the table that should be returned.

Examples

Example 1: Display a random value from table "tbl1" using default roll:
[r: table("tbl1")]

Example 2: Display the first value from table "tbl1":

[r: table("tbl1", 1)]

Example 3: Display one of the first four values from "tbl1", chosen randomly:

[r: table("tbl1", "1d4")]

Example 4: Display a table row that corresponds to a token property's value (the value must be numeric):

[r: table("tbl1", Intelligence)]
[r: table("tbl1", getProperty("PCLevel"))]

Example 5: Evaluate the outcome of a table entry. The table entry must thus be something that can be evaluated, like 1d10 or roll(1,6) or 3+5:

[r: eval(table("tbl1"))]

Example 5: Evaluate the outcome of a table entry that contains code. The table entry can thus contain code, but its not required. 'code' in this case is anything between [brackets]. An example table entry could be [h:roll=1d20]You [r:if(roll<10, 'hit', 'miss')] your target. :

[r: evalMacro(table("tbl1"))]

See Also

tableImage()
There is a tool available to import tables from excel. You can find more about this here