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 .
×
If you opened a D&D 2024 character on July 17 between 2:20 PM ET and 4:40 PM ET, and now see that your character data is missing/blank, please make a copy of your game and perform a rollback. Rollbacks have been enabled for all users during this period.
Create a free account

Selecting an ability based on user input

1486566055
Ulti
Pro
Sheet Author
API Scripter
I would like to create a macro that calls some ability depending on a choice by the user. Here is my tentative, where i have two abilities defined for a given token, Bow and Sword : %{selected|?{Weapon?|Bow|Sword}} --ambush I first get a message that there is no ability found for %{Bow|Sword}, then I get to chose, and it displays selected|Bow --ambush What would be the correct way to write what I want?
I would switch the query with the ability call by using it this way ?{Weapon|Bow,%{selected|Bow}|Sword,%{selected|Sword}} However, if there are any "|", ",", or "}" inside the %{Bow} or %{Sword} you will need to replace them with "|", ",", "}" respectively. For more information as to why this is necessary please see  here . As an aside, what is the purpose of the --ambush in your macro?
1486566832
Ziechael
Forum Champion
Sheet Author
API Scripter
Beat to it by Kyle :P For your reference I would familiarise yourself with the  Dice Reference page of the wiki, specifically the  Order of Operations which details the order in which the various aspects of a macro are resolved, in this case the ability is attempting to resolve itself before the query has even been addressed which gives you the "no ability found for %{Bow|Sword}" output.
1486567349
Ulti
Pro
Sheet Author
API Scripter
First, many thanks for the quick reply. The solution seems to work perfectly. I must admit, though, that I don't quite understand the evaluation order. Using your solution, I first selected a target (both abilities require a target to be selected), then selected the weapon. I wonder how that would work out if both abilities didn't use the same input variables..
1486575726
Lithl
Pro
Sheet Author
API Scripter
If you follow the "Order of Operations" link Ziechael provided, you'll see that the engine does things in a particular order: Abilities are expanded (%{XXXX} gets replaced by the contents of the ability) Macros are expanded (#XXXX gets replaced by the contents of the macro), including nested macros Attributes are substituted (@{XXXX} gets replaced by the contents of the attribute) Roll queries are executed (?{XXXX} gives you a prompt and then gets replaced by what you enter in the prompt) Steps 1-4 are repeated until there are no abilities, macros, variables, or roll queries left (letting you put macros in attributes, for example) Inline rolls are executed ([[XXXX]] is processed), starting with the most deeply nested and working upwards The rest of the roll is executed: Dice are rolled Functions (floor, ceil, etc.) are evaluated The remaining formula is evaluated In this case, the original macro "%{selected|?{Weapon?|Bow|Sword}}" would try to find an ability named "?{Weapon?|Bow|Sword}", and fail. Kyle's version starts with "?{Weapon|Bow,%{selected|Bow}|Sword,%{selected|Sword}}"; at step 1 it becomes "?{Weapon|Bow,bow ability text|Sword,sword ability text}", and then at step 4 you pick between Bow and Sword, getting one of the results.
Hi! I have a similar problem and i'm not yet sure how to solve it.  Kyle G. said: I would switch the query with the ability call by using it this way ?{Weapon|Bow,%{selected|Bow}|Sword,%{selected|Sword}} However, if there are any "|", ",", or "}" inside the %{Bow} or %{Sword} you will need to replace them with "|", ",", "}" respectively.  Where exactly does this change need to be made? Inside the abilities Bow and Sword code? Or directly in the ability call?  A example would be great! Thanks
1486609514

Edited 1486609935
João Cartaxo said: Hi! I have a similar problem and i'm not yet sure how to solve it.  Kyle G. said: I would switch the query with the ability call by using it this way ?{Weapon|Bow,%{selected|Bow}|Sword,%{selected|Sword}} However, if there are any "|", ",", or "}" inside the %{Bow} or %{Sword} you will need to replace them with "|", ",", "}" respectively.  Where exactly does this change need to be made? Inside the abilities Bow and Sword code? Or directly in the ability call?  A example would be great! Thanks For example if you have two ability macros abilityA: ?{Do something|Yay!|Nope} and abilityB: ?{Do something else|0} If you wanted to combine these macros into a single macro, you could: ?{Macro?|Something,%{selected|macroA}|Something Else,%{selected|macroB}}. The problem is that the macro query will end at the first "}" it finds which currently would be (we know this because of the Order of Operations listed above ?{Macro?|Something,?{Do something|Yay!|Nope } |Something Else,?{Do something else|0}}  In order to successfully get this combination macro to work we will need to change the "|", ",", and "}" inside #macroA and #macroB into their HTML equivalents "|", "&44;", and "}". So abilityA would be ?{Do something|Yay!|Nope} and abilityB would be ?{Do something else&124;0&125; Now our combination macro would work correctly. Do note that now neither macroA, nor macroB will work on their own because their individual nested queries are broken.
Thanks Kyle! I realized now that what i'm trying to accomplish is a  little different and more complex. As the OP, i would like to create a macro that calls some ability depending on a choice by the user, but with the following structure: ?{Attribute|Agility,%{selected|Agility}|Smarts,%{selected|Smarts}|Spirit,%{selected|Spirit}|Strength,%{selected|Strength}|Vigor,%{selected|Vigor}} Each of the five choices is defined as below, just changing the name: &{template:solidtrait}{{name=@{selected|character_name}}} {{skill_name=Agility}} {{skill_rank=@{agility}}} {{ttmod=@{ttmod}}} {{wounds= -[[@{woundsMod}]]}} {{fatigue= -[[@{fatigue}]]}} {{skill_roll=[[1d@{agility}! + ?{Modifier|0} [Modifier] - @{wounds} [Wounds] - @{fatigue}[Fatigue]]]}} {{wild_die_rank=@{wilddie}}} {{wild_die=[[1d@{wilddie}! [Wild die] + ?{Modifier|0} [Modifier]- @{wounds}[Wounds] -@{fatigue}[Fatigue]]]}} This HTML thing is driving me crazy...  :(
1486720111

Edited 1486720134
Ziechael
Forum Champion
Sheet Author
API Scripter
João Cartaxo said: &{template:solidtrait}{{name=@{selected|character_name}}} {{skill_name=Agility}} {{skill_rank=@{agility}}} {{ttmod=@{ttmod}}} {{wounds= -[[@{woundsMod}]]}} {{fatigue= -[[@{fatigue}]]}} {{skill_roll=[[1d@{agility}! + ?{Modifier|0} [Modifier] - @{wounds} [Wounds] - @{fatigue}[Fatigue]]]}} {{wild_die_rank=@{wilddie}}} {{wild_die=[[1d@{wilddie}! [Wild die] + ?{Modifier|0} [Modifier]- @{wounds}[Wounds] -@{fatigue}[Fatigue]]]}} This HTML thing is driving me crazy...  :( I feel your pain, essentially you need to make the html conversion on each } , and | within the ability you are 'nesting' within the original query so that when the attribute is resolved (before the query is due to the order of operations) it pulls through, converting the html into the syntax without recognising the syntax on the first pass... if that makes sense lol. The forums also eat html so you have to do some further nesting here for display purposes but here is an example of what each ability should look like (note that you don't have to do replacements on the attribute calls): &{template:solidtrait}{{name=@{selected|character_name}}} {{skill_name=Agility}} {{skill_rank=@{agility}}} {{ttmod=@{ttmod}}} {{wounds= -[[@{woundsMod}]]}} {{fatigue= -[[@{fatigue}]]}} {{skill_roll=[[1d@{agility}! + ?{Modifier|0} [Modifier] - @{wounds} [Wounds] - @{fatigue}[Fatigue]]]}} {{wild_die_rank=@{wilddie}}} {{wild_die=[[1d@{wilddie}! [Wild die] + ?{Modifier|0} [Modifier]- @{wounds}[Wounds] -@{fatigue}[Fatigue]]]}}
1486720438

Edited 1486720593
João Cartaxo said: @{woundsMod} From the SW-Tabbed sheet's HTML , it looks like woundsMod is an auto-calculating Attribute with a value of {(@{NoS}+@{wounds}),0}kh1. Like with Abilities, any HTML entity replacements needs to be make within the value ("code") of Attributes. Unfortunately, it is not possible to edit the values of autocalculated Attributes. So, in order to properly use this auto-calculating Attribute within a Roll Query, every one of its Attribute calls would need to be replaced with its Current value, which can then be subject to HTML entity replacements. That is to say, every instance of @{woundsMod} would need to be replaced with {(@{NoS}+@{wounds}),0}kh1 That said, in your case, it is possible (and recommended) to avoid using Advanced Roll Queries by reconfiguring your macro like so: &{template:solidtrait} {{name=@{selected|character_name} }} {{skill_name=?{Attribute|Agility, [Agility] (@{selected|agility})|Smarts, [Smarts] (@{selected|smarts})|Spirit, [Spirit] (@{selected|spirit})|Strength, [Strength] (@{selected|strength})|Vigor, [Vigor] (@{selected|vigor}} }} {{ttmod=@{selected|ttmod} }} {{wounds= -[[ @{selected|woundsMod} ]] }} {{fatigue= -[[ @{selected|fatigue} ]] }} {{skill_roll=[[ 1d[[?{Attribute} + 0d0]]! + ?{Modifier|0} [Modifier] - @{selected|wounds} [Wounds] - @{selected|fatigue}[Fatigue] ]] }} {{wild_die_rank=@{selected|wilddie} }} {{wild_die=[[ 1d@{selected|wilddie}! [Wild die] + ?{Modifier} [Modifier] - @{selected|wounds} [Wounds] - @{selected|fatigue}[Fatigue] ]] }} &{template:solidtrait} {{name=@{selected|character_name}}} {{skill_name=?{Attribute|Agility, [Agility] (@{selected|agility})|Smarts, [Smarts] (@{selected|smarts})|Spirit, [Spirit] (@{selected|spirit})|Strength, [Strength] (@{selected|strength})|Vigor, [Vigor] (@{selected|vigor}}}} {{ttmod=@{selected|ttmod}}} {{wounds= -[[ @{selected|woundsMod} ]]}} {{fatigue= -[[ @{selected|fatigue} ]]}} {{skill_roll=[[ 1d[[?{Attribute} + 0d0]]! + ?{Modifier|0} [Modifier] - @{selected|wounds} [Wounds] - @{selected|fatigue}[Fatigue] ]]}} {{wild_die_rank=@{selected|wilddie}}} {{wild_die=[[ 1d@{selected|wilddie}! [Wild die] + ?{Modifier} [Modifier] - @{selected|wounds} [Wounds] - @{selected|fatigue}[Fatigue] ]]}}
Thank you all for your help! It worked like a charm!  :)
Hello again! I recently fount out that the much more streamlined roll associated with the direct roll from the Savage Words Tabbed sheet: @{selected|defsTemplate} @{selected|rolltAgility} gives out the same output as: &{template:solidtrait}{{name=@{selected|character_name}}} {{skill_name=Agility}} {{skill_rank=@{agility}}} {{ttmod=@{ttmod}}} {{wounds= -[[@{woundsMod}]]}} {{fatigue= -[[@{fatigue}]]}} {{skill_roll=[[1d@{agility}! + ?{Modifier|0} [Modifier] - @{wounds} [Wounds] - @{fatigue}[Fatigue]]]}} {{wild_die_rank=@{wilddie}}} {{wild_die=[[1d@{wilddie}! [Wild die] + ?{Modifier|0} [Modifier]- @{wounds}[Wounds] -@{fatigue}[Fatigue]]]}} I created following abilities: Agility: @{selected|defsTemplate} @{selected|rolltAgility} Smarts: @{selected|defsTemplate} @{selected|rolltSmarts} ?{Attribute|Agility,%{selected|Agility} |Smarts,%{selected|Smarts}} Any ideas on how can i reproduce the behaviour that  Silvyre suggested with this new approach? I can't seem to make it work. Thanks
Unfortunately, that approach cannot work with Roll Queries for reasons outlined in Advanced Usage for Roll Queries and Roll Query Troubleshooting .
Hi Silvyre! I suspected roll20 had some limitations on this issue. The example you gave me above worked perfectly, but i forgot an important detail, two stats; Agility and Strength, have a conditional modifier, @{Encumbrance} that is not applicable to the other 3 stats, so i'm not really sure how do accomplish this with the example that already worked, all my attempts failed. Any suggestions? Perhaps using the API command buttton to get a menu in the chat box? Thanks for you support and patience!
What looks more correct: 1d@{agility}! + @{Encumbrance}, or 1d[[@{agility} + @{Encumbrance}]]!
Hi,  1. Is correct as only the stat roll explodes, all modifiers are added afterwards. 
Try this out: &{template:solidtrait} {{name=@{selected|character_name} }} {{skill_name=?{Attribute|Agility, [Agility] (1d@{selected|agility}! + @{Encumbrance})|Smarts, [Smarts] (1d@{selected|smarts}!)|Spirit, [Spirit] (1d@{selected|spirit}!)|Strength, [Strength] (1d@{selected|strength}! + @{Encumbrance})|Vigor, [Vigor] (1d@{selected|vigor}!} }} {{ttmod=@{selected|ttmod} }} {{wounds= -[[ @{selected|woundsMod} ]] }} {{fatigue= -[[ @{selected|fatigue} ]] }} {{skill_roll=[[ ?{Attribute} + ?{Modifier|0} [Modifier] - @{selected|wounds} [Wounds] - @{selected|fatigue}[Fatigue] ]] }} {{wild_die_rank=@{selected|wilddie} }} {{wild_die=[[ 1d@{selected|wilddie}! [Wild die] + ?{Modifier} [Modifier] - @{selected|wounds} [Wounds] - @{selected|fatigue}[Fatigue] ]] }}
1487115122

Edited 1487115224
Hi Silvyre, First of all, thank you very much for your awesome support! What you suggested worked, with a minor tweak i forgot to mention before, it was not @{Encumbrance} but @{selected|encumbrance} that should have been used. This is the current code so far: &{template:solidtrait} {{name=@{selected|character_name} }} {{skill_name=?{Attribute|Agility, [Agility] (1d@{selected|agility}! + @{selected|encumbrance})|Smarts, [Smarts] (1d@{selected|smarts}!)|Spirit, [Spirit] (1d@{selected|spirit}!)|Strength, [Strength] (1d@{selected|strength}! + @{selected|encumbrance})|Vigor, [Vigor] (1d@{selected|vigor}!} }} {{ttmod=@{selected|ttmod} }} {{enc= [[ @{selected|encumbrance} ]] }} {{wounds= -[[ @{selected|woundsMod} ]] }} {{fatigue= -[[ @{selected|fatigue} ]] }} {{skill_roll=[[ ?{Attribute} + ?{Modifier|0} [Modifier] - @{selected|wounds} [Wounds] - @{selected|fatigue}[Fatigue] ]] }} {{wild_die_rank=@{selected|wilddie} }} {{wild_die=[[ 1d@{selected|wilddie}! [Wild die] + ?{Modifier} [Modifier] - @{selected|wounds} [Wounds] - @{selected|fatigue}[Fatigue] ]] }} I'm not sure if you are familiar with Savage worlds rules, but when a character rolls a trait (attribute or skill) he always rolls two dice, the attribute/skill dice plus a wild die (generally a d6) and keeps the higher one, all modifiers are added afterwards to this roll. In a standard roll, it would be something like this: /r {1d?{Trait Die|6}! , 1d6!}kh1 + ?{Modifier|0} With the Savage Worlds Tabbed template, as far as i can tell, the wild die is separated from the trait roll, as shown in the examples I've been posting. In the code you are suggesting is it possible to replicate this behavior with this sheet? Can the same encumbrance modifier added to the trait be added to the wild die?  Another thing, nothing special, has to do with the resulting visual difference. The result from code above is a little different from the standard sheet roll, as shown in the below images. The next image is the result rolled directly from the sheet: Result from the sheet Result from code above Is it possible to streamline the output from the code? Thanks once again!! Cheers
At this point, it's probably best to shift over to an Advanced Roll Query: &{template:solidtrait} {{name=@{selected|character_name} }} {{ttmod=[[@{selected|ttmod}]] }} {{enc=[[@{selected|encumbrance}]] }} {{wounds= [[@{selected|woundsMod}*-1]] }} {{fatigue= [[@{selected|fatigue}*-1]] }} {{skill_name=?{Attribute|   Agility, Agility}} {{skill_rank=@{selected|Agility}}} {{skill_rank_mod=@{selected|agMod}}} {{att_mod=[[@{selected|agrollMod}]]}} {{skill_roll=[[ {1d@{selected|agility}![Agility], 1d@{selected|wilddie}![Wild Die]}kh1 +@{selected|agMod}[Agility Rank Modifier] + @{selected|agrollMod}[Agility Roll Modifier] + @{selected|encumbrance}[Encumbrance Penalty] |   Smarts, Smarts}} {{skill_rank=@{selected|Smarts}}} {{skill_rank_mod=@{selected|smMod}}} {{att_mod=[[@{selected|smrollMod}]]}} {{skill_roll=[[ {1d@{selected|smarts}![Smarts], 1d@{selected|wilddie}![Wild Die]}kh1 +@{selected|smMod}[Smarts Rank Modifier] + @{selected|smrollMod}[Smarts Roll Modifier] |   Spirit, Spirit}} {{skill_rank=@{selected|Spirit}}} {{skill_rank_mod=@{selected|spMod}}} {{att_mod=[[@{selected|sprollMod}]]}} {{skill_roll=[[ {1d@{selected|spirit}![Spirit], 1d@{selected|wilddie}![Wild Die]}kh1 +@{selected|spMod}[Spirit Rank Modifier] + @{selected|sprollMod}[Spirit Roll Modifier] |   Strength, Strength}} {{skill_rank=@{selected|Strength}}} {{skill_rank_mod=@{selected|stMod}}} {{att_mod=[[@{selected|strollMod}]]}} {{skill_roll=[[ {1d@{selected|strength}![Strength], 1d@{selected|wilddie}![Wild Die]}kh1 +@{selected|stMod}[Strength Rank Modifier] + @{selected|strollMod}[Strength Roll Modifier] + @{selected|encumbrance}[Encumbrance Penalty] |   Vigor, Vigor}} {{skill_rank=@{selected|Vigor}}} {{skill_rank_mod=@{selected|viMod}}} {{att_mod=[[@{selected|virollMod}]]}} {{skill_roll=[[ {1d@{selected|vigor}![Vigor], 1d@{selected|wilddie}![Wild Die]}kh1 +@{selected|viMod}[Vigor Rank Modifier] + @{selected|virollMod}[Vigor Roll Modifier]   } + @{selected|ttmod}[Trait Test Modifier] - @{selected|woundsMod}[Wounds] - @{selected|fatigue}[Fatigue] ]] }}
Hi Silvyre, It works perfectly!! Did you remove the ?{Modifier|0} [Modifier] option for some particular reason? Once again, thanks for your support! Cheers
Glad it works! João Cartaxo said: Did you remove the ?{Modifier|0} [Modifier] option for some particular reason? Ah; I forgot to add that to what I pulled from the HTML . Fortunately, it's easy enough to insert that Query into the second-to-last line of the macro.
Hi Silvyre, Solved all my issues, with your awesome help! Thanks
You're very welcome! Happy rolling!