RPTools.net

Discussion and Support

Skip to content

It is currently Thu Jul 27, 2017 9:53 am 






Reply to topic  [ 6 posts ] 

Previous topic | Next topic 

  Print view

Author Message
 Offline
Kobold
 
Joined: Sun Apr 23, 2017 6:57 pm
Posts: 3
 Post subject: Help using checkboxes and collecting their values
PostPosted: Mon Apr 24, 2017 12:35 am 
Okay, hopefully this is a simple thing that I'm just not getting.

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:
[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 gives me a dialog box that looks like this:
Image

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:
*snip*
  </table>
  </body>
</html>
}]

[H: countChecked = if(json.contains(strength, 1), countChecked + 1, countChecked)]

and the macro runs, but I get the message

Quote:
Unknown JSON type "" in function "json.contains".


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.


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Fri Mar 20, 2009 4:40 am
Posts: 9269
Location: Netherlands
 Post subject: Re: Help using checkboxes and collecting their values
PostPosted: Mon Apr 24, 2017 2:26 am 
you've apparently mist a vital part while reading the tutorial: http://lmwcs.com/rptools/wiki/Forms_tutorial


Quote:
Now lets make my little form work:

[h: processorLink = macroLinkText("processForm@Lib:token", "all")]
<form action="[r:processorLink]" method="json">
Character name: <input type="text" name="charName"><br>
Strength: <input type="text" name="str"><br>
<input type="submit" name="myForm_btn" value="Okay">
</form>
And create the processForm-macro.

<pre>
[r: json.indent(macro.args,2)]
</pre>
With this setup we can very easily find out how a specific form packs the data entered and how we could work with that. For this tutorial this processForm-macro will do.

The output we receive from this example is

{
"charName": "the fishy dude",
"str": "7",
"myForm_btn": "Okay"
}
Now its pretty easy to access the name and strength using json.get().


point is you require the
Code:
[h: processorLink = macroLinkText("processForm@Lib:token", "all")]
<form action="[r:processorLink]" method="json">
line which calls the macro 'processForm' on the library token "lib:token" (which you can change to any other token) in processForm you can check the json with:
Code:
[r: json.indent(macro.args,2)]

_________________
GETTING STARTED WITH MAPTOOLS - TUTORIALS, DOCS, VIDEOS, TOOLS, ETC

My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent and
DPI.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS


Top
 Profile  
 
 Offline
Kobold
 
Joined: Sun Apr 23, 2017 6:57 pm
Posts: 3
 Post subject: Re: Help using checkboxes and collecting their values
PostPosted: Tue Apr 25, 2017 4:44 am 
wolph42 wrote:
you've apparently mist a vital part while reading the tutorial: http://lmwcs.com/rptools/wiki/Forms_tutorial


You are correct. That's exactly the thing I needed to get back on track. It took a bit of swearing and drinking, but I finally got a working tool.

Image


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Fri Mar 20, 2009 4:40 am
Posts: 9269
Location: Netherlands
 Post subject: Re: Help using checkboxes and collecting their values
PostPosted: Tue Apr 25, 2017 7:42 am 
good to hear you got it working!!

_________________
GETTING STARTED WITH MAPTOOLS - TUTORIALS, DOCS, VIDEOS, TOOLS, ETC

My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent and
DPI.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS


Top
 Profile  
 
User avatar  Offline
Demigod
 
Joined: Sun Feb 25, 2007 11:53 am
Posts: 3635
Location: MD
 Post subject: Re: Help using checkboxes and collecting their values
PostPosted: Tue Apr 25, 2017 2:58 pm 
Jewish_Monk wrote:
You are correct. That's exactly the thing I needed to get back on track. It took a bit of swearing and drinking, but I finally got a working tool.

You should post the working code for others to scavenge.

_________________
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."


Top
 Profile  
 
 Offline
Kobold
 
Joined: Sun Apr 23, 2017 6:57 pm
Posts: 3
 Post subject: Re: Help using checkboxes and collecting their values
PostPosted: Tue Apr 25, 2017 7:02 pm 
Well, if you insist. It's not perfect and it's certainly not pretty, but it works.

Be Aware:
    - You'll need a token named Lib:Anarchy to hold the "rollTwoStats" macro
    - A custom set of properties should be set for each character (Strength, Agility, Hacking, etc). This is a side effect of Anarchy being so free-form with its skills. Every character could have 4-6 skills unique to them.
    - Each individual character will need to have the HTML portion of the "Dice Pool" macro tailored to their individual skills. I would have had this generate automatically, but I called it quits at 4am. That may be the next step for me.
    - If the token is not actively selected when the Roll button is pushed, there will be a 0 dice pool. Trying to figure out a way around this
    - The dialog does not actually enforce only two checkboxes. I considered implementing that, but I think it would be better to output the player's choices and police things manually.

"Dice Pool" macro - add to token
Code:
[h: processorLink = macroLinkText("rollTwoStats@Lib:Anarchy", "all")]
[h: id = getSelected()]

[H: dialogName = getName() + "'s Dice Pool" ]
[frame(dialogName): {
<html>
  <head>
    <title>[R: dialogName]</title>
    <link rel="stylesheet" type="text/css" href="css@Lib:Anarchy"></link>
  </head>
  <body>
  <form action="[R: processorLink]" method="json">
  <table>
    <th colspan = 4>Please select two</th>
    <tr class="odd">
      <td align="right">Strength: [r: getProperty("Strength", id)]</td>
      <td>
        <input type="checkbox" name="strength" value="1" />
      </td>
      <td align="right">Escape Artist: [r: getProperty("Escape Artist", id)]</td>
      <td>
        <input type="checkbox" name="escape artist" value="1" />
      </td>
    </tr>
    <tr class="even">
      <td align="right">Agility: [r: getProperty("Agility", id)]</td>
      <td>
        <input type="checkbox" name="agility" value="1" />
      </td>
      <td align="right">Sorcery: [r: getProperty("Sorcery", id)]</td>
      <td>
        <input type="checkbox" name="sorcery" value="1" />
      </td>
    </tr>
    <tr class="odd">
      <td align="right">Willpower: [r: getProperty("Willpower", id)]</td>
      <td>
        <input type="checkbox" name="willpower" value="1" />
      </td>
      <td align="right">Astral Combat: [r: getProperty("Astral Combat", id)]</td>
      <td>
        <input type="checkbox" name="astral combat" value="1" />
      </td>
    </tr>
    <tr class="even">
      <td align="right">Logic: [r: getProperty("Logic", id)]</td>
      <td>
        <input type="checkbox" name="logic" value="1" />
      </td>
      <td align="right">Survival: [r: getProperty("Survival", id)]</td>
      <td>
        <input type="checkbox" name="survival" value="1" />
      </td>
    </tr>
    <tr class="odd">
      <td align="right">Charisma: [r: getProperty("Charisma", id)]</td>
      <td>
        <input type="checkbox" name="charisma" value="1" />
      </td>
      <td align="right">Engineering: [r: getProperty("Engineering", id)]</td>
      <td>
        <input type="checkbox" name="engineering" value="1" />
      </td>
    </tr>
    <tr>
      <td align="right" class="even">Edge: [r: getProperty("Edge", id)]</td>
      <td class="even">
        <input type="checkbox" name="edge" value="1" />
      </td>
      <td align="right"></td>
      <td></td>
    </tr>
    <tr>
      <td colspan = 2 align = right class="odd">x2<input type="checkbox" name="xx" value="1" />
      x3<input type="checkbox" name="xxx" value="1" /></td>
      <td></td>
      <td></td>
    </tr>
    <tr>
      <td colspan="4" align="center">
      <input tabindex="2" name="Button" type="submit" value="      Roll!      " />
      </td>
    </tr>
  </table>
  </form>
  </body>
</html>
}]


"rollTwoStats" macro - add to Lib:Anarchy
Code:
<!-- Shadowrun UltraAnarchy macro -->
<!-- Initialize variables -->
[h: statBlock = json.indent(macro.args,2)]
[h: id = getSelected()]
[h: dicePool = 0]

[r, foreach(var, statBlock, ""), code: {
  [h: newDie = getProperty(var, id)]

  [r, if(var != "Button" && var != "xx" && var != "xxx"), code:{
    [h: dicePool = dicePool + newDie]
  };{}] <!--IF-->

}] <!--FOREACH-->

[r, foreach(var, statBlock, ""), code: {

  [r, if(var == "xx"), code:{
    [h: dicePool = dicePool * 2]
  };{}] <!--IF-->

}] <!--FOREACH-->

[r, foreach(var, statBlock, ""), code: {

  [r, if(var == "xxx"), code:{
    [h: dicePool = dicePool * 3]
  };{}] <!--IF-->

}] <!--FOREACH-->

[r: "<br>Dice Pool = "][r: dicePool]
[r: sr4(dicePool)]


Top
 Profile  
 
Display posts from previous:  Sort by  
Reply to topic  [ 6 posts ] 

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:

Who is online

In total there are 2 users online :: 1 registered, 0 hidden and 1 guest (based on users active over the past 5 minutes)
Most users ever online was 243 on Sun Nov 04, 2012 6:14 am

Users browsing this forum: Bing [Bot] and 1 guest





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

Style based on Andreas08 by Andreas Viklund

Style by Elizabeth Shulman