formatStrProp: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
m (Text replacement - "<source" to "<syntaxhighlight")
 
(4 intermediate revisions by 3 users not shown)
Line 4: Line 4:


|usage=
|usage=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h: formatStrProp(props, listFormat, entryFormat, separator) ]
[h: formatStrProp(props, listFormat, entryFormat, separator) ]
</source>
</syntaxhighlight>
* listFormat is a string that is emitted once. It should contain the text "%list", which is replaced with the formatted items.
* listFormat is a string that is emitted once. It should contain the text "%list", which is replaced with the formatted items.
* entryFormat is emitted once per item. Any instances of "%key" and "%value" in the string are replaced with the key or value for that setting.
* entryFormat is emitted once per item. Any instances of "%key" and "%value" in the string are replaced with the key or value for that setting.
Line 12: Line 12:


|example=
|example=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h: props = "Strength=14 ; Constitution=8 ; Dexterity=13 ; Intelligence=4 ; Wisdom=18 ; Charisma=9"]
[h: props = "Strength=14 ; Constitution=8 ; Dexterity=13 ; Intelligence=4 ; Wisdom=18 ; Charisma=9"]
[formatStrProp(props, "<table border=1>%list</table>", "<tr> <td><b>%key</b></td> <td>%value</td> </tr>", "")]   
[formatStrProp(props, "<table border=1>%list</table>", "<tr> <td><b>%key</b></td> <td>%value</td> </tr>", "")]   
</source>
</syntaxhighlight>
(prints settings in a formatted table)
 
Outputs:
 
<table border=1>
<tr><td><b>Strength</b></td><td>14</td></tr>
<tr><td><b>Constitution</b></td><td>8</td></tr>
<tr><td><b>Dexterity</b></td><td>13</td></tr>
<tr><td><b>Intelligence</b></td><td>4</td></tr>
<tr><td><b>Wisdom</b></td><td>18</td></tr>
<tr><td><b>Charisma</b></td><td>9</td></tr>
</table>
 
}}
}}
[[Category:String Property List Function]]
[[Category:String Property List Function]]

Latest revision as of 21:13, 14 March 2023

formatStrProp() Function

Returns a custom-formatted version of the property string.

Usage

[h: formatStrProp(props, listFormat, entryFormat, separator) ]
  • listFormat is a string that is emitted once. It should contain the text "%list", which is replaced with the formatted items.
  • entryFormat is emitted once per item. Any instances of "%key" and "%value" in the string are replaced with the key or value for that setting.
  • separator is emitted in between the formatted items.

Example

[h: props = "Strength=14 ; Constitution=8 ; Dexterity=13 ; Intelligence=4 ; Wisdom=18 ; Charisma=9"]
[formatStrProp(props, "<table border=1>%list</table>", "<tr> <td><b>%key</b></td> <td>%value</td> </tr>", "")]

Outputs:

Strength14
Constitution8
Dexterity13
Intelligence4
Wisdom18
Charisma9