Help regarding a tutorial

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

Post Reply
WinterduskVampire
Cave Troll
Posts: 26
Joined: Thu May 31, 2012 9:00 pm

Help regarding a tutorial

Post by WinterduskVampire »

Well this is my first time here on the forums and I'm really looking forward to working with MapTool and Macros. I have some experince with scripting languages (various c like stuff used as event stuff in various video games mostly, and some experience with Java).

I'm currently using MapTool version 1.3.b87.

After doing some stuff with json objects (and getting frustrated) I decided to try fulfilling my coding needs with a simpler approach (simpler than json objects anyway) and followed one of the tutorials on the MapTool Wiki. I'm working off of the Introduction to Dialogs and Frames Tutorial. I've noticed available frameworks, but I guess I'm just a stubborn one and insist on building my own stuff, but wanted to use the tutorial as a foundation to then build on.

So I followed this tutorial almost perfectly to the letter (only changing things like the name of the Library Token I use in my campaign, and left out the traffic light bar stuff). However whenever I try to go to use the new "weapons" page of the tutorials character sheets I get an error. So I hunted through the macros, starting with the tutorials EditWeaponDialog macro. I could run that macro, and get the pop-up form correctly, I'd enter the some data into it, use the save button, and then the macro would prompt me for input for "Weapons". I could put something in the input and I would simply get the error that "setStrProp()" requires exactly 1 parameters. For reference "Weapons" is already added to the campaign properties for tokens.

I went over the EditWeaponDialog macro and found no use of the setStrProp function, so I tracked back from EditWeaponDialog macro to the macro it called, which is the AddWeapon Macro from the tutorial which does use the setStrProp function. However I can't figure out what is wrong with the macro. D:

First here is the Add Weapon Macro from my campaign:

Code: Select all

[h: num = getStrProp(macro.args, "Number")]

[h: damage = getStrProp(macro.args, "Damage")]

[h: name = getStrProp(macro.args, "Name")]

[h: bonus = getStrProp(macro.args, "Bonus")]

[h: Weapons = setStrProp(Weapons, strformat("Weapon%{num}Name"), name)]

[h: Weapons = setStrProp(Weapons, strformat("Weapon%{num}Damage"), damage)]

[h: Weapons = setStrProp(Weapons, strformat("Weapon%{num}Bonus"), bonus)]


And the EditWeaponDialog Macro from my campaign:

Code: Select all


  [dialog("weaponInput"): {

      [h: weaponNum = getStrProp(macro.args, "Number")]

      [h: name = getStrProp(macro.args, "Name")]

      [h: bonus = getStrProp(macro.args, "Bonus")]

      [h: damage = getStrProp(macro.args, "Damage")]

      <!-- If we do not have a weapon number grab the next one -->

      [h, if(weaponNum == ""), code: {

        [h,macro("NextWeaponNumber@this"): ""]

        [h: weaponNum = macro.return]

      }]

      <html>

        <head>

          <title>Edit Weapon Dialog</title>

          <meta name="input" content="true">

          <link rel="stylesheet" type="text/css" href="EditWeapon_css@[r: getMacroLocation()]">

        </head>

        <body>

          <form name="weaponInput" action="[r:macroLinkText('AddWeapon@Lib:CharSheet')]">

            <table>

              <tr>

                <td>

                  <table>

                    <tr>

                      <th>

                        <label for="Name">Weapon Name</label>

                      </th>

                      <td>

                        <input type="text" name="Name" value="[r: name]">

                        </input> <br>

                      </td>

                    </tr>

                    <tr>

                      <th>

                        <label for="Damage">Weapon Damage</label>

                      </th>

                      <td>

                        <input type="text" name="Damage" value="[r: damage]">

                        </input> <br>

                      </td>

                    </tr>

                    <tr>

                      <th>

                        <label for="Bonus">Weapon Bonus</label>

                      </th>

                      <td>

                        <input type="text" name="Bonus" value="[r: bonus]">

                        </input>

                      </td>

                    </tr>

                  </table>

                </td>

                <td>

                  <img src='[r: getTokenImage(100)]'></img>

                </td>

              </tr>

            </table>

            <!-- hidden input with the weapon number -->

            <input type="hidden" name="Number" value="[r: weaponNum]">

            </input>

            <input id="saveButton" type="submit" name="Save" value="Save">

            </input>

          </form>

        </body>

      </html>

    }]



I've also noticed that the weapon number is increased in the "Weapons" entry on a token, but the entered data that was put into the form doesn't get added to the "Weapons" entry on the token properties.

I'm unsure what is not working here exactly. I realized it could be a number of things including such as:
1. Is there a bug in this version of MapTool or some change to the way these functions are used since the tutorial was written?
2. Is it that the token being refereed to is lost in the changes between one Macro to the next?
3. Is it that the Macro text link function isn't doing something right in terms of passing the data along to the add weapon?
4. Maybe something in the EditWeaponDialog html table stuff I'm missing?
4. Something else I've missed? *facedesk*

Thank you for all your help.

User avatar
aliasmask
RPTools Team
Posts: 9031
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: Help regarding a tutorial

Post by aliasmask »

When creating the Wiki: macroLinkText() you'll want to include the Wiki: currentToken() id, otherwise when you reference "Weapons" it doesn't reference the token. Also, use of the attribute "id" and the tag "label" aren't supported. Otherwise, your code looks like it should work. You can save a couple of lines of code by using Wiki: varsFromStrProp().

WinterduskVampire
Cave Troll
Posts: 26
Joined: Thu May 31, 2012 9:00 pm

Re: Help regarding a tutorial

Post by WinterduskVampire »

Ok, I'll try your suggestions and add target to the macro using the current token and maybe put to use the variables from string function.

If "label" and "id" are not supported, what should I use in their place?

User avatar
aliasmask
RPTools Team
Posts: 9031
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: Help regarding a tutorial

Post by aliasmask »

Well, label is easy. Just put the text to display and if you need to set a value use a hidden input. I don't know why you're using id, but if it is for formatting, just use a class. Another note about classes.. MT only supports one class name per tag, so if you need multiple classes you'll have to add a span around it. Also, and this is a major buzz kill, no css works on the input elements.

WinterduskVampire
Cave Troll
Posts: 26
Joined: Thu May 31, 2012 9:00 pm

Re: Help regarding a tutorial

Post by WinterduskVampire »

Ok, so I removed the mentioned id and name stuff and those worked fine it seems. Put in place a currenttoken() reference for id under the macrotextlink etc.

I also seemed to have some sort of error that would come up with it telling me the line:

Code: Select all

[h,if(isPropertyEmpty("Weapons")): Weapons = "NumWeapons=0;"]
This line in NextWeaponNumber and GetWeaponNumbers kept returning that there was an invalid condition error in the if statement. Also it appeared that while "Weapons" is being set to "NumWeapons=0;" that Weapons entry doesn't appear to be actually tied to the "Weapons" property on the token as it seems to just be defining the local variable "Weapons" instead of getting it from the current token. So I replaced that line with:

Code: Select all

[h:Weapons = getProperty("Weapons", currentToken())]
[h, if(Weapons == ""): Weapons = "NumWeapons=0;"]
So, now currently in those macros after making that change, I get the error that "Error executing "getProperty": the token name or id "" is unknown." even though I'm just using currentToken().

I'm also getting an error with the character sheet for some reason where the section with getTokenImage(100):

Code: Select all



[h:StatisticNames = "Strength, Dexterity, Constitution, Intelligence, Wisdom, Charisma"]

<table>
<tr>
<td>
<img src='[r: getTokenImage(100)]'></img>
</td>
<td>

<table id="stats">
<tr>
<th>Name</th>
<th>Score</th>
</tr>

[h: class = "oddRow"]
[foreach(stat, StatisticNames, ""),CODE:
{
<tr class="[r:class]">
<td>[r:stat]</td>
<td>[r:getProperty(stat)]</td>
</tr>
[h: class = if(class=="oddRow", "evenRow", "oddRow")]
}]

</td>
</tr>
</table>

<hr>

<table>
<tr>
<th>Hit Points:</th>
<td>[r: HitPointsShown]</td>
</tr>
<tr>
<th>Defense:</th>
<td>[r: Defense]</td>
</tr>
</table>

The image appears to show up ok, but I get the error in chat that "java.lang.NullPointerException error executing expression getTokenImage(100)."

Thank you for your continued help.

WinterduskVampire
Cave Troll
Posts: 26
Joined: Thu May 31, 2012 9:00 pm

Re: Help regarding a tutorial

Post by WinterduskVampire »

Hm...ok...I seem to have gotten the character sheet to work, it appears I had to impersonate the token to get it to work.

I get the error with the no id for the token if I'm not impersonating anything, even if I have clicked and the little highlight box has appeared around a token. The image error I'm getting also doesn't appear if I've impersonated a token.

Is there a way to resolve that, or is it suppose to be that way?

I was hoping I'd be able to use that character sheet stuff for any creature including NPC's without having to directly impersonate them.

Any ideas/suggestions?

User avatar
Bone White
Great Wyrm
Posts: 1124
Joined: Tue Aug 23, 2011 11:41 am
Location: Cornwall, UK

Re: Help regarding a tutorial

Post by Bone White »

If you wish to use a token's id without using impersonation, use Wiki: getSelected(), but bear in mind if you select multiple tokens it will generate a string list instead of a single string. Many properties have an optional parameter to insert the id of the token being altered e.g. Wiki: setProperty(), which you can specify with the id obtained using getSelected.

WinterduskVampire
Cave Troll
Posts: 26
Joined: Thu May 31, 2012 9:00 pm

Re: Help regarding a tutorial

Post by WinterduskVampire »

Ok I'll try that with the setup I've got so far. How to I, say I'm bringing up someone's character sheet, if I accidentally selected several tokens when doing so, how can I script things so as to not give an error and mess up when it tries to do stuff with those multiple tokens?

User avatar
Bone White
Great Wyrm
Posts: 1124
Joined: Tue Aug 23, 2011 11:41 am
Location: Cornwall, UK

Re: Help regarding a tutorial

Post by Bone White »

[code=php][h: selected = getSelected()]
[h, if(listCount(selected) > 1): assert(0,"You must only select one token",0)] [/code]


Alternatively, my custom defined function (selectSelected()) which you can just copy/paste into the top of your macro, it makes the user pick the token it wants to target from a list instead of generating the "You must only select one token" line from before:

[code=php][h: bw.playerTokenIDList = getSelected()]
[h: bw.playerTokenNameList =""]
[h, foreach(tokenID,bw.playerTokenIDList): bw.playerTokenNameList = listAppend(bw.playerTokenNameList,getName(tokenID))]

[h: bw.listLength = listCount(bw.playerTokenNameList)]

[h, if (bw.listLength <= 0), code :{
    [h: assert(0,"You have no tokens selected!",0)]
    };{
    }
]

[h, if (bw.listLength > 1), code :{
    [h: abort(input(
    "bw.playerTokenIndex|"+bw.playerTokenNameList+"|Choose which token to use|LIST|Select = 0"
    ))]
    };{
    [h: bw.playerTokenIndex = 0]
    }
]

[h: playerTokenName = listGet(bw.playerTokenNameList,bw.playerTokenIndex)]
[h: playerTokenID = listGet(bw.playerTokenIDList,bw.playerTokenIndex)] [/code]

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Help regarding a tutorial

Post by wolph42 »

Bone White wrote:

Code: Select all

[h, if(listCount(selected) > 1): assert(0,"You must only select one token",0)] 
funny, the whole point of the 'assert' function is that you can make direct assertions with it so:

Code: Select all

[h: assert(listCount(selected)==1,"Make sure you have (only) one token selected",0)]  
This will also abort the function properly if you have NO tokens selected, which is also a circumstance you need to keep in check.

moxou
Kobold
Posts: 5
Joined: Wed May 04, 2016 1:40 pm

Re: Help regarding a tutorial

Post by moxou »

Hello
I'm new with Maptool.
I'm starting to make my own game framework
I've fool the Introduction to Dialogs and Frames tutorial

I have the same trouble than you and none of the solution don't work for me

Did you solve it
Tks
Guillaume

Post Reply

Return to “Macros”