json.objrolls: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
(Created page with "Is similar to json.rolls() but returns a json object. It takes 3 parameters json.objrolls(names, stat, rolls) This will generate rolls for all the stat for each "name". roll...")
 
No edit summary
 
(6 intermediate revisions by 4 users not shown)
Line 1: Line 1:
Is similar to json.rolls() but returns a json object.
{{MacroFunction
It takes 3 parameters
|name=json.objrolls
|proposed=false
|trusted=false
|version=1.4.0.5
|description=
Is similar to {{func|json.rolls}} but returns a JSON object.


|usage=
<syntaxhighlight lang="mtmacro" line>
json.objrolls(names, stat, rolls)
json.objrolls(names, stat, rolls)
</syntaxhighlight>


This will generate rolls for all the stat for each "name". rolls is either a single string with a roll expression in which case every stat will use same roll expression, or a json array with a roll expression for each stat (so must be same size as stat).
'''Parameters'''
{{param|names|A JSON array containing the names to be used for each group.}}
{{param|stat|A JSON array with the stat names.}}
{{param|rolls|Either a single string containing a dice roll expression or a JSON array of dice roll expressions.}}


This will generate rolls for each stat in a group for each "name". Rolls is either a single string with a roll expression in which case every stat will use same roll expression, or a json array with a roll expression for each stat (so must be same size as stat).


e.g.
''Example:''<syntaxhighlight lang="mtmacro" line>
<pre>{json.indent(json.objrolls("['henchman1', 'henchman2', 'henchman3']", "['Str', 'Dex', 'Con', 'Int', 'Wis', 'Chr']", "3d6"),2)}</pre>
{json.indent(json.objrolls("['henchman1', 'henchman2', 'henchman3']",
        "['Str', 'Dex', 'Con', 'Int', 'Wis', 'Chr']",
        "3d6"),2)}
</syntaxhighlight>


 
<pre>code:{  "henchman1":  {
code:{  "henchman1":  {
     "Str": 10,
     "Str": 10,
     "Dex": 12,
     "Dex": 12,
Line 34: Line 48:
     "Wis": 15,
     "Wis": 15,
     "Chr": 13
     "Chr": 13
   }}
   }}</pre>


''Example:''<syntaxhighlight lang="mtmacro" line>
{json.indent(json.objrolls("['henchman1', 'henchman2', 'henchman3']",
        "['Str', 'Dex', 'Con', 'Int', 'Wis', 'Chr']",
        "['3d6+1', '3d6', '3d6', '3d6-2', '3d6', '2d6']"),2)}
</syntaxhighlight>


<pre>{json.indent(json.objrolls("['henchman1', 'henchman2', 'henchman3']", "['Str', 'Dex', 'Con', 'Int', 'Wis', 'Chr']", "['3d6+1', '3d6', '3d6', '3d6-2', '3d6', '2d6']"),2)}</pre>
<pre>code:{  "henchman1":  {
 
code:{  "henchman1":  {
     "Str": 11,
     "Str": 11,
     "Dex": 12,
     "Dex": 12,
Line 62: Line 79:
     "Wis": 13,
     "Wis": 13,
     "Chr": 7
     "Chr": 7
   }}
   }}</pre>
 
|also=
[[Introduction to JSON Datatypes ]], {{func|json.rolls}}
[[Category:JSON Function]]
}}

Latest revision as of 23:59, 15 March 2023

json.objrolls() Function

Introduced in version 1.4.0.5
Is similar to json.rolls() but returns a JSON object.

Usage

json.objrolls(names, stat, rolls)

Parameters

  • names - A JSON array containing the names to be used for each group.
  • stat - A JSON array with the stat names.
  • rolls - Either a single string containing a dice roll expression or a JSON array of dice roll expressions.

This will generate rolls for each stat in a group for each "name". Rolls is either a single string with a roll expression in which case every stat will use same roll expression, or a json array with a roll expression for each stat (so must be same size as stat).

Example:

{json.indent(json.objrolls("['henchman1', 'henchman2', 'henchman3']",
        "['Str', 'Dex', 'Con', 'Int', 'Wis', 'Chr']",
        "3d6"),2)}
code:{  "henchman1":   {
    "Str": 10,
    "Dex": 12,
    "Con": 10,
    "Int": 10,
    "Wis": 8,
    "Chr": 12
  },
       "henchman2":   {
    "Str": 11,
    "Dex": 10,
    "Con": 7,
    "Int": 13,
    "Wis": 9,
    "Chr": 7
  },
       "henchman3":   {
    "Str": 10,
    "Dex": 10,
    "Con": 10,
    "Int": 12,
    "Wis": 15,
    "Chr": 13
  }}

Example:

{json.indent(json.objrolls("['henchman1', 'henchman2', 'henchman3']",
        "['Str', 'Dex', 'Con', 'Int', 'Wis', 'Chr']",
        "['3d6+1', '3d6', '3d6', '3d6-2', '3d6', '2d6']"),2)}
code:{  "henchman1":   {
    "Str": 11,
    "Dex": 12,
    "Con": 13,
    "Int": 8,
    "Wis": 10,
    "Chr": 11
  },
        "henchman2":   {
    "Str": 12,
    "Dex": 11,
    "Con": 12,
    "Int": 8,
    "Wis": 12,
    "Chr": 3
  },
        "henchman3":   {
    "Str": 12,
    "Dex": 13,
    "Con": 9,
    "Int": 8,
    "Wis": 13,
    "Chr": 7
  }}


See Also