Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Question about Attribute Altering API in Nesting Macro

1717566952
Rogue
Pro
Marketplace Creator
I'm wondering if anyone knows of an API Script that can alter an attribute like Mana or Chi when they are used in a nesting macro. I use token macros so you do not have to open the sheet for everything but I am wondering if there is anyway to alter an attribute using an API script if it is within a nesting macro. Something like ChatSetAtt or Ammo maybe? The token macro looks something like this... &{template:simple} {{name=@{character_name} Cast Check}} {{text=?{Spell List |@{Spell1Name},[[d20+@{selected|Spell1HitMod}@{MenMod}+?{Modifier|0} [@{Spell1Name}_Cast] ]] **@{Spell1Name}** Mana Drain: **@{Spell1Drain}**  Area: **@{Spell1Area}** Magic Actions: **@{Spell1Act}** |@{Spell2Name},[[d20+@{selected|Spell2HitMod}@{MenMod}+?{Modifier|0} [@{Spell2Name}_Cast] ]] **@{Spell2Name}**
1717603050
timmaugh
Forum Champion
API Scripter
I'm not sure what you mean by "nesting" in this case... I tend to think of nesting as when one macro is used inside another. Are you referring to the fact that you need the script call to operate inside your query? ChatSetAttr-only Option ChatSetAttr offers a way to run even in a non-script message (like this one currently is) by wrapping the CSA command line in: ! ... !!! CSA will listen to all messages and scan for this formation. If CSA finds this text pattern  with a CSA handle  (like setattr, delattr, etc.), it runs the command. When you do this (embed a CSA command in a non-script message), CSA doesn't have the time to remove the detected text from the command line before the message gets rendered to chat (it runs in "parallel"), so typically you would want to put your embedded command between template parts so that it won't show, anyway: &{template:simple}{{name=@{character name} Cast Check}} !setattr --sel --mana|-[[1d4]] !!! {{text=?{Spell List|... There, the command is between the template parts, but not part of the query. If there will be a different mana cost for each spell, you might need to include the ChatSetAttr call as a part of the query, but still between template parts. That would mean that the query would encompass at least the opening of the template part "text": &{template:simple}{{name=@{character name} Cast Check}}  ?{Spell List | @{Spell1Name}, !setattr --sel --mana|-[[1d4]] !!! {{text=... | @{Spell2Name},!setattr --sel --mana|-[[1d4+1]] !!! {{text=... | ... } }} I believe you can also include whole template parts as the value of the adjustment, and CSA will use the first inline roll as the amount to do the modification while leaving the template part behind, so that might be an option, as well. Not sure. You'd have to play with having the query completely wrap the {{text}} template part (which will be made ugly with HTML replacements), and placing the query in an argument of the CSA line with the mana adjustment being first (before the template part in the query option) if it would even work: &{template:simple}{{name=@{character name} Cast Check}} !setattr --sel ?{Spell List |--mana&pipe;-[[1d4]] {{text= @{Spell1Name},[[d20+@{selected|Spell1HitMod}@{MenMod}+?{Modifier|0} [@{Spell1Name}_Cast] ]] **@{Spell1Name}** Mana Drain: **@{Spell1Drain}**  Area: **@{Spell1Area}** Magic Actions: **@{Spell1Act}** }} |...} !!! I'm not even sure if that will work, but it  might  be possible with some careful attention to HTML replacements. It would also be a bit difficult to edit/update later, as you'd have to first parse your way through all of the embedded-ness, through all of the HTML replacements-es, and then do the same replacement-izing to your new text to make sure it will work. Of course, there might be a way to do this with metascripts and make the whole thing (somewhat) more readable. Let me know if you're open to that sort of option and I'll see if I can work it up for you.
1717985929
Rogue
Pro
Marketplace Creator
Yes, you are right! I wanted to place it inside the query. First of all thanks for answering back. Ever since we made these sheets for Demon Gate I have been wanting to find a way to cut down on clicks and to  try to make things as user friendly and easy for new players as possible. As it is currently, these are token macros that call upon all the spells on your character sheet. Then once you click the spell you wish to cast it rolls your d20 for you to cast, and it displays some of the spell information for you, one of which is mana drain. I wanted to have it take the drain that is displayed in the chat box off of the sheet for you without having to manually negate it from your bubble but seems like a lot.