Need help with simple HP-rolling macro

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
User avatar
Dachimotsu
Kobold
Posts: 14
Joined: Wed Apr 02, 2014 3:00 pm

Need help with simple HP-rolling macro

Post by Dachimotsu »

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: Select all

[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.

User avatar
Full Bleed
Demigod
Posts: 4736
Joined: Sun Feb 25, 2007 11:53 am
Location: FL

Re: Need help with simple HP-rolling macro

Post by Full Bleed »

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."

User avatar
Dachimotsu
Kobold
Posts: 14
Joined: Wed Apr 02, 2014 3:00 pm

Re: Need help with simple HP-rolling macro

Post by Dachimotsu »

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.

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Need help with simple HP-rolling macro

Post by aliasmask »

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: Select all

<!-- 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: Select all

*@HP(Hit Points): [r: HP = 2d6]
I recommend you read some best practices from here: http://forums.rptools.net/viewtopic.php ... 81#p233681

And some more on code writing wolph42 compiled here: http://forums.rptools.net/viewtopic.php ... 49#p252549

User avatar
Full Bleed
Demigod
Posts: 4736
Joined: Sun Feb 25, 2007 11:53 am
Location: FL

Re: Need help with simple HP-rolling macro

Post by Full Bleed »

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: Select all

[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."

User avatar
Dachimotsu
Kobold
Posts: 14
Joined: Wed Apr 02, 2014 3:00 pm

Re: Need help with simple HP-rolling macro

Post by Dachimotsu »

Full Bleed wrote:

Code: Select all

[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".

User avatar
Full Bleed
Demigod
Posts: 4736
Joined: Sun Feb 25, 2007 11:53 am
Location: FL

Re: Need help with simple HP-rolling macro

Post by Full Bleed »

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: Select all

[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."

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Need help with simple HP-rolling macro

Post by aliasmask »

Properties with a space in them hurts on a mental level and will likely get you in trouble down the line.

User avatar
Full Bleed
Demigod
Posts: 4736
Joined: Sun Feb 25, 2007 11:53 am
Location: FL

Re: Need help with simple HP-rolling macro

Post by Full Bleed »

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."

Post Reply

Return to “Macros”