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

Query multiple commands

So I have used Chatsetattr to create a token action for stat changes for example for a bladesinger I have the 2 scripts

Astrea begins bladesinging


!setattr --silent --sel --repeating_acmod_$0_global_ac_active_flag|1


!setattr --name Astraea Darvose --silent --evaluate --constitution_save_bonus|%intelligence_mod% + %constitution_mod%


!setattr --silent --sel --mod --other_resource|-1


and 


Astrea stops bladesinging


!setattr --silent --sel --repeating_acmod_$0_global_ac_active_flag|0


!setattr --name Astraea Darvose --silent --evaluate --constitution_save_bonus|%constitution_mod%


I would like to know if there's a way to query between the two scripts rather than have 2 seperate token actions listed, the few attempts I have made have not functioned properly (I am new to writing scripts)

January 29 (2 years ago)

Edited February 19 (2 years ago)
timmaugh
Forum Champion
API Scripter

You *can* do it with HTML replacements (escaping the query-control characters [comma, vertical pipe, and right brace] where the appear in the command lines you shared so that the don't affect the query), but you have to make sure you don't escape the same characters that are involved in a sheet- or token-call (ie, @{selected|the_thing}), because they'd want to resolve BEFORE the query. Plus, once escaped, the command lines would *only* work as a part of a query, so that the characters would have time to "re-encode" (starting as , doesn't break the query, so the query runs and that HTML encoded character becomes an actual comma, so that now, after the query resolved, if the comma was needed for your ChatSetAttr call,it would be there.

I find the Fetch alternative much easier, and it preserves the ability for your ability to call each individual command on their own, not as a part of a query. If you have fetch installed, you just have to use the Fetch construction to refer to wherever you stored the command lines. If you stored them on the Astrea character as abilities names BladesingingOn and BladesingingOff, the query could be either of:

?{Turn Bladesinging...|On,@(Astrea.Bladesinging-On)|Off,@(Astrea.Bladesinging-Off)}

Or...

@(Astrea.Bladesinging-?{Turn Bladesinging...|On|Off})

With other metascripts (Fetch is a metascript), you could even detect the state of Bladesinging in or to toggle it on/off... Removing the need to even answer the query prompt, if you wanted.


If you want an example of that, post back. It's equally straightforward.

February 18 (2 years ago)

Edited February 18 (2 years ago)

I've not seen fetch at all so far so an example would be great, thank you very much

?{Turn Bladesinging...|On,@(Astrea.Bladesinging-On|Off,@(Astrea.Bladesinging-Off)} doesn't seem to work. Actually let me try something as I'm typing this


February 18 (2 years ago)

So I have the macros set in the characters attributes and abilities

The macro might be failing because the character name is "Astrea Darvose" and I'm not sure if the space in it is making it not select the sheet properly

February 19 (2 years ago)

Edited February 19 (2 years ago)
timmaugh
Forum Champion
API Scripter

I had a typo in what I provided - sorry. I fixed it above, but I'll outline it here, too.

This first approach would require Fetch and ZeroFrame. Once you've installed both, you can use formations like this:

@(Character Name.attribute)
%(Character Name.ability)

... to retrieve information.  So, for Astrea Darvose, the two attributes would be:

%(Astrea Darvose.Bladesinging-On)
%(Astrea Darvose.Bladesinging-Off)

So you can do a query in two different ways using those constructions. Since the constructions don't include any control characters for a query (a comma, vertical pipe, or right brace), you can use them inside a query:

?{Turn Bladesinging...|On,%(Astrea Darvose.Bladesinging-On)|Off,%(Astrea Darvose.Bladesinging-Off)}

...or, since these formations resolve after Roll20 parsing, you can use the roll query inside the fetch construction, and let it supply the building parts:

%(Astrea Darvose.Bladesinging-?{Turn Bladesinging...|On|Off})

The trick is that these Fetch constructions are metascript constructions, and only work in a bangsy message (starting with a bang: ! ). So you'd have something more like:

!?{Turn Bladesinging...|On,%(Astrea Darvose.Bladesinging-On)|Off,%(Astrea Darvose.Bladesinging-Off)}

(I could have used the other query and made the same alteration). That message will prompt you for the choice, and based on your selection, return the proper Fetch construction to the command line (either 'on' or 'off').

!%(Astrea Darvose.Bladesinging-On)

Then the message gets sent to the script moderator (since it's a bangsy message), and Fetch replaces the Bladesinging-On formation with the attribute contents -- your ChatSetAttr command lines:

!Astrea begins bladesinging
!setattr --silent ...
!setattr --name ...
!setattr --silent

You see that the first one looks like a bangsy message, even though it should just be sent to the chat. Also, what you're left with is a series of commands that you want to be sent separately, but which are all going to be present in this one message. To get around this, let's change the Bladesinging-On and -Off abilities.

We'll wrap the existing lines in the ZeroFrame batching construction: !{{ ... }}

That will issue each command separately. Also, we'll use the {&simple} formation to make sure the first line makes it to chat. We'll have to defer it so that it doesn't stop the initial message (only the dispatched, individual line):

!{{
  (^)Astrea begins bladesinging{^&simple}
  !setattr --silent --sel --repeating_acmod_$0_global_ac_active_flag|1
  !setattr --name Astraea Darvose --silent --evaluate --constitution_save_bonus|%intelligence_mod% + %constitution_mod%
  !setattr --silent --sel --mod --other_resource|-1
}}

Then do the same thing for the other ability, too. These abilities will still run if you activate them individually, and they'll be more consistent since they won't be subject to the bug where the Roll20 parsers occasionally drop random lines from a multi-line command. However, wrapping them this way will let them also function when you pull them into the ability macro where you have your query (if you pull them in with the Fetch construction).

TL;DR Version

Change the Bladesinging-On ability to be:

!{{
  (^)Astrea begins bladesinging{^&simple}
  !setattr --silent --sel --repeating_acmod_$0_global_ac_active_flag|1
  !setattr --name Astraea Darvose --silent --evaluate --constitution_save_bonus|%intelligence_mod% + %constitution_mod%
  !setattr --silent --sel --mod --other_resource|-1
}}

Change the Bladesinging-Off ability to be:

!{{
  (^)Astrea stops bladesinging{^&simple}
  !setattr --silent --sel --repeating_acmod_$0_global_ac_active_flag|0
  !setattr --name Astraea Darvose --silent --evaluate --constitution_save_bonus|%constitution_mod%
}}

Change the calling command to be:

!?{Turn Bladesinging...|On,%(Astrea Darvose.Bladesinging-On)|Off,%(Astrea Darvose.Bladesinging-Off)}

See if that works better

Caveats

I'm not as familiar with the ChatSetAttr commands themselves, so I'm not looking at them. Also, if they (or any command you're bringing in as a part of a Fetch construction) contains character sheet references (like retrieving an attribute or ability), those references need to be fully qualified (including the character name). Even though the shorthand versions will work from a character sheet (ie, @{underwater_macrame} instead of @{Astrea Darvose|underwater_macrame} ), we're pulling them in *after* the Roll20 parsers have had a chance at them. In other words, those shorthand constructions will no longer work because they won't pass through the Roll20 process (only our metascript process).

Scripts Required

Fetch (one-click) and ZeroFrame Beta



February 19 (2 years ago)
timmaugh
Forum Champion
API Scripter

APILogic Version

You can have a version that detects whether the character is currently bladesinging or not, so that it activates the appropriate macro. Install APILogic, and then change the calling macro. We'll remove the query, and instead use a conditional check:

!{&if @{Astrea Darvose|repeating_acmod_$0_global_ac_active_flag} = 0}%\(Andrea Darvose.Bladesinging-On){&else}%\(Andrea Darvose.Bladesinging-Off){&end}

That should work just as well. Note that I used the ZeroFrame deferral of a backslash to defer the detection of the Fetch constructions. This is because by default, with Fetch, APILogic, and ZeroFrame installed, Fetch will run before APILogic. By deferring the Fetch constructions, we don't retrieve the one we want until after the APILogic conditional gets evaluated.

In any case, this command line should now detect whether or not it needs to turn the Bladesinging on or off depending on the status of the character. You'd use the same command in either direction.

Give either the APLogic version or the Fetch query version a try and post back if you have any issues.

Oh wow thank you, sorry about the lack of response, I've been very busy


But if this does work it'll be fantastic because it can also be adapted to giants might a lycanthropy blood hunter and a spore druid I have between a couple of games