RPTools.net

Discussion and Support

Skip to content

It is currently Wed Nov 22, 2017 5:23 pm 






Reply to topic  [ 9 posts ] 

Previous topic | Next topic 

  Print view

Author Message
User avatar  Offline
Kobold
 
Joined: Wed Apr 02, 2014 2:00 pm
Posts: 11
 Post subject: Need help with simple HP-rolling macro
PostPosted: Wed Nov 01, 2017 10:40 pm 
So, I'm trying to make a macro that will roll the HP of a horde of goblins for me. The one I've got right now works fine, except it only works for one token at a time:

Code:
[h: Property = "Hit Points"]
[h: Value = 2d6]
[h: ID = getSelected()]
[h: setProperty(Property, Value, ID)]
<b>Hit Points:</b> [r: getProperty ("Hit Points")]


But when I make copies of the token, highlight them all, and try to use the macro as a "common macro", I get this error:

Error executing "setProperty": the token name or id "000000009D04C47A8A74000000000000,00000000970E89794120000000000000" is unknown.

I made an initiative-rolling macro before that works fine as a common macro, but I can't figure out what to do with this one.


Top
 Profile  
 
User avatar  Offline
Demigod
 
Joined: Sun Feb 25, 2007 11:53 am
Posts: 3774
Location: MD
 Post subject: Re: Need help with simple HP-rolling macro
PostPosted: Thu Nov 02, 2017 12:32 am 
Dachimotsu wrote:
I made an initiative-rolling macro before that works fine as a common macro, but I can't figure out what to do with this one.

In the macro editor check "Apply to Selected Tokens" (bottom left).

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


Top
 Profile  
 
User avatar  Offline
Kobold
 
Joined: Wed Apr 02, 2014 2:00 pm
Posts: 11
 Post subject: Re: Need help with simple HP-rolling macro
PostPosted: Thu Nov 02, 2017 1:06 am 
Full Bleed wrote:
Dachimotsu wrote:
I made an initiative-rolling macro before that works fine as a common macro, but I can't figure out what to do with this one.

In the macro editor check "Apply to Selected Tokens" (bottom left).


Well, that's probably a step that needed to be taken, but I'm still getting the error.
What's more, is that my initiative macro doesn't need that box checked to function properly.


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Tue Nov 10, 2009 6:11 pm
Posts: 7949
Location: Bay Area
 Post subject: Re: Need help with simple HP-rolling macro
PostPosted: Thu Nov 02, 2017 5:42 am 
When you use getSelected it returns all the id you have selected, that's why you have 2 ids. You need to get them individually. In this case, I wouldn't use apply to selected otherwise you'll roll for all the tokens for each token. ie 2 tokens = 4 rolls, 3 tokens = 9 rolls...

Code:
<!-- token properties need to follow naming guidelines, see below -->
[h: Property = "HP"]
[h: Value = 2d6]
<!-- I'm using a json instead of a string list so I can loop through the list easier -->
[h: ids = getSelected("json")]
<!-- create an output variable to store your output instead of dumping to screen immediately -->
[H: output = "[]"]
[h, foreach(id,ids), code: {
   <!-- set the current token from the list -->
   [h: switchToken(id)]
   <!-- don't need to use id anymore because current token is set -->
   [h: setProperty(Property, Value)]
   <!-- one of many ways to store your output -->
   [H: output = json.append(output,"<b>Hit Points:</b> %s",getProperty (Property))]
}]
<!-- put line breaks between each entry -->
[R: json.toList(output,"<BR>")]


But the above can all be avoided if you just set your token property with a default value like this. In this example, HP is the property name and Hit Points is what is displayed in the stat sheet. The default value is set and overwrites the formula.:
Code:
*@HP(Hit Points): [r: HP = 2d6]


I recommend you read some best practices from here: viewtopic.php?f=20&t=22886&p=233681#p233681

And some more on code writing wolph42 compiled here: viewtopic.php?f=3&t=25077&p=252549#p252549

_________________
Downloads:


Top
 Profile  
 
User avatar  Offline
Demigod
 
Joined: Sun Feb 25, 2007 11:53 am
Posts: 3774
Location: MD
 Post subject: Re: Need help with simple HP-rolling macro
PostPosted: Thu Nov 02, 2017 12:29 pm 
Dachimotsu wrote:
Well, that's probably a step that needed to be taken, but I'm still getting the error.
What's more, is that my initiative macro doesn't need that box checked to function properly.

While Alias is providing some good information, it strikes me as (probably) more complicated than you were looking for.

I think if you select "Apply to Selected" you will just need to remove the Wiki: getSelected() function to get the result you want. That is... to make it do what you said you wanted to do: Select a bunch of tokens and generate Hit Points with a macro.

Code:
[h: value = 2d6]
[h: setProperty("Hit Points", value)]
<b>Hit Points:</b> [r: getProperty("Hit Points")]


That said, I'm not sure what you mean by "common macro" though... so understanding where you're using the macro would help tailor something to your particular case.

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


Top
 Profile  
 
User avatar  Offline
Kobold
 
Joined: Wed Apr 02, 2014 2:00 pm
Posts: 11
 Post subject: Re: Need help with simple HP-rolling macro
PostPosted: Thu Nov 02, 2017 12:44 pm 
Full Bleed wrote:
Code:
[h: value = 2d6]
[h: setProperty("Hit Points", value)]
<b>Hit Points:</b> [r: getProperty("Hit Points")]


That said, I'm not sure what you mean by "common macro" though... so understanding where you're using the macro would help tailor something to your particular case.


YES, this is exactly what I needed. Works perfectly. Thank you very much.

And "common macro" is a term I found in MapTool itself. When you highlight multiple tokens that share a macro, the shared macros appear at the top of the "selection" window, under a category called "Common Macros".


Top
 Profile  
 
User avatar  Offline
Demigod
 
Joined: Sun Feb 25, 2007 11:53 am
Posts: 3774
Location: MD
 Post subject: Re: Need help with simple HP-rolling macro
PostPosted: Thu Nov 02, 2017 1:22 pm 
Dachimotsu wrote:
And "common macro" is a term I found in MapTool itself. When you highlight multiple tokens that share a macro, the shared macros appear at the top of the "selection" window, under a category called "Common Macros".

Oh, ok. That's for when you have the macro on both tokens and it's one that they have "in common".

You could, for example, make a GM token with your monster creation macros on it (like this one). Impersonate it and use the macro from the impersonate window. Select your new monster tokens, and then run the HP generator on them. That way you would not need to have this macro on each monster token.

Or you could just put this macro in your Campaign Macros and run it from there on your monster tokens.

Either way, if you're going to be doing it this way a lot you might want to have a more general monster creator macro that you could run from your Campaign Macro window or a GM token.

Something like:

Code:
[h:status=input(
   "junk|<html><b>Monster Setup</b><br><br></html>|<html>Tooltip Text Here</html>|LABEL|SPAN=TRUE",
   "hitDice|0|Hit Dice",
   "armorClass|0|AC"
   )
]
[h:abort(status)]

[h: monsters = getSelected()]

[h, FOREACH (monster, monsters), CODE:
   {
      [h: setProperty("AC", armorClass, monster)]
      [h: rolledHPs = eval(hitDice)]
      [h: setProperty("Hit Points", rolledHPs, monster)]
      [h: broadcast("<b>"+getName(monster)+"</b>", "GM")]
      [h: broadcast("Hit Points: "+rolledHPs, "GM")]
      [h: broadcast("AC: "+armorClass, "GM")]
   }
]


This way you could add new input lines for additional data to be generated on the tokens.

Note that you *would not* use "Apply to selected" with this macro because you're "getting the selected" tokens from within the macro itself.

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


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Tue Nov 10, 2009 6:11 pm
Posts: 7949
Location: Bay Area
 Post subject: Re: Need help with simple HP-rolling macro
PostPosted: Thu Nov 02, 2017 1:31 pm 
Properties with a space in them hurts on a mental level and will likely get you in trouble down the line.

_________________
Downloads:


Top
 Profile  
 
User avatar  Offline
Demigod
 
Joined: Sun Feb 25, 2007 11:53 am
Posts: 3774
Location: MD
 Post subject: Re: Need help with simple HP-rolling macro
PostPosted: Thu Nov 02, 2017 1:42 pm 
aliasmask wrote:
Properties with a space in them hurts on a mental level and will likely get you in trouble down the line.

Heh... so true! You can only set them using Wiki: setProperty()... which is a pain. I rarely use that function.

There is always a balance between throwing too much info at a new macro user and guiding them to best practices though... so I went with the property they used since I don't know how prolific it is in their current usage... but if it's not too much trouble, I'd definitely switch to "HP" or "HitPoints" as a property name over "Hit Points" if I was the OP.

And, while we're at it, when using variables: Only Captialize Token Properties in macros. That way you can identify quickly when you're using a temporary variable (it's lower case) or calling on a Token Property. I see this one all the time on the forums... and like spaces in token properties... I always grind my teeth a little when I do. ;)

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


Top
 Profile  
 
Display posts from previous:  Sort by  
Reply to topic  [ 9 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 is 1 user online :: 0 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: No registered users and 1 guest





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

Style based on Andreas08 by Andreas Viklund

Style by Elizabeth Shulman