I'm attempting to make some macros for Shadowrun Anarchy. All that needs to happen is the players tick one box for a skill, one for an attribute, and the macro should retrieve their numbers, add them together, and roll xd6. Simple.
First, this is a bit of dummy code to hold the skill and attribute ranks until I can make it prettier.
Code: Select all
[H: countChecked = 0]
[H: dialogName = getName() + "'s Dice Pool" ]
[dialog(dialogName): {
<html>
<head>
<title>[R: dialogName]</title>
</head>
<body>
<table>
<tr>
<td align="right">Strength</td>
<td>
<input type="checkbox" name="strength" value="0" />
</td>
<td align="right">Hacking</td>
<td>
<input type="checkbox" name="hacking" value="0" />
</td>
</tr>
<tr>
<td align="right">Agility</td>
<td>
<input type="checkbox" name="agility" value="0" />
</td>
<td align="right">Driving</td>
<td>
<input type="checkbox" name="driving" value="0" />
</td>
</tr>
<tr>
<td align="right">Willpower</td>
<td>
<input type="checkbox" name="willpower" value="0" />
</td>
<td align="right">Sorcery</td>
<td>
<input type="checkbox" name="sorcery" value="0" />
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input tabindex="2" name="Button" type="submit" value="Roll" />
<input tabindex="3" name="Button" type="submit" value="Cancel" /></td>
<td align="right">Checked?</td>
<td>
[R: countChecked]
</td>
<td></td>
</tr>
</table>
</body>
</html>
}]
That's great, but I can't quite figure out how to detect if any checkboxes have been ticked. The wiki says that "The variable is assigned either 0 (unchecked) or 1 (checked)."
The Forms tutorial also mentions checkboxes. Says to "test if a box is checked by using json.contains on the field name."
So I tried a simple test to see if the Strength box was ticked.
Code: Select all
*snip*
</table>
</body>
</html>
}]
[H: countChecked = if(json.contains(strength, 1), countChecked + 1, countChecked)]
None of those parameters are strings. Doesn't make any sense. I get that this test doesn't check if the box has been unticked, but I'll worry about that later. I feel like if I could just determine which boxes are ticked, I could send that info to another macro to retrieve the property values and be done with it.Unknown JSON type "" in function "json.contains".