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 with different insertion values

Hi, I have a macro in which I want the result of a single query to insert text into the displayed name, and a number into the die roll. This is the gist (note, I added an extra space after each pipe symbol in the query so that it displays more legibly here in this forum): {{name=Roll Using ?{Attribute?|  Strength,STR| Dexterity,DEX| Constitution,CON| Intelligence,INT| Wisdom,WIS| Charisma,CHA} Modifier}} {{roll=1d20+?{Attribute?| Strength,@{cn|STR_mod}| Dexterity,@{cn|DEX_mod}| Constitution,@{cn|CON_mod}| Intelligence,@{cn|INT_mod}| Wisdom,@{cn|WIS_mod}| Charisma,@{cn|CHA_mod}} Unfortunately, the query inserts whatever replacement value occurs first in the macro in both places, instead of paying attention to what comes after the pipe symbol in each instance of the query. If I put the {{roll}} part first in this macro, the query gets the correct modifier for the d20 roll, but that number appears in the name instead of the three-letter text abbreviation. If I put the {{name}} part first in this macro, the roll attempts to add the three-letter text to the d20 roll instead of the appropriate number. Is there a way to do this kind of replacement? I tried to do it by using the query output as part of the name of an existing value, like this, but I think it fails due to order-of-operations, because it gives me a " No attribute was found for @{cn|?{Attribute?} " error: @{cn|?{Attribute?| Strength,STR| Dexterity,DEX| Constitution,CON| Intelligence,INT| Wisdom,WIS| Charisma,CHA}_mod} I would be fine with inserting the displayed label of the selected query as the text, instead of a replacement value (so in this case, inserting Strength, Dexterity, etc instead of STR, DEX, etc in the name would be fine). If this kind of query replacement is not possible, I will resort to using "nesting a macro in a roll query" after creating separate macros RollUsingStrength, RollUsingDexterity, etc. My only issue there is that I actually want to do something considerably more complicated than what I described above, using multiple queries as input, which means I would need to create a separate macro for each possible combination of queries -- and even then, I don't know if I can nest "nesting a macro in a roll query" inside of another roll query, so I might have to create a single ugly query that lists out every possible combination as individual choices. Oof. Thanks in advance for help and advice.
1575708077

Edited 1575708145
Kraynic
Pro
Sheet Author
The problem is that you are asking the same question.  With a query, once you have answered it once in a macro, that query will automatically be answered that way any other time it occurs in the macro.  So you need to word your second query differently from the first.  You would need to change the second question to something like "Attribute Modifier?" or something.  That does mean you would be answering 2 queries though.
1575710699
Ziechael
Forum Champion
Sheet Author
API Scripter
The only way around that limitation is when you are dealing purely with numerical values or are prepared to have everything past the initial query be the result of the query, it gets real messy real quick and requires html replacements for offending characters but for simple things it isn't too tricky, for example: &{template:default} {{name=Roll Using ?{Attribute|Strength,STR Modifier}} {{roll=[[1d20+@{cn|STR_mod}]]|Dexterity,DEX Modifier}} {{roll=[[1d20+@{cn|DEX_mod}]]|Constitution,CON Modifier}} {{roll=[[1d20+@{cn|CON_mod}]]|Intelligence,INT Modifier}} {{roll=[[1d20+@{cn|INT_mod}]]|Wisdom,WIS Modifier}} {{roll=[[1d20+@{cn|WIS_mod}]]|Charisma,CHA Modifier}} {{roll=[[1d20+@{cn|CHA_mod}]]} }}
1575712913
GiGs
Pro
Sheet Author
API Scripter
George T.  said: I tried to do it by using the query output as part of the name of an existing value, like this, but I think it fails due to order-of-operations, because it gives me a " No attribute was found for @{cn|?{Attribute?} " error: @{cn|?{Attribute?| Strength,STR| Dexterity,DEX| Constitution,CON| Intelligence,INT| Wisdom,WIS| Charisma,CHA}_mod} Just to address this: you are correct this is failing because of the order of operations. You cannot build up attribute calls from queries (or any similar ideas), because attribute calls are processed before queries are.
Ziechael said: The only way around that limitation is when you are dealing purely with numerical values or are prepared to have everything past the initial query be the result of the query, it gets real messy real quick and requires html replacements for offending characters but for simple things it isn't too tricky, for example: &{template:default} {{name=Roll Using ?{Attribute|Strength,STR Modifier}} {{roll=[[1d20+@{cn|STR_mod}]]|Dexterity,DEX Modifier}} {{roll=[[1d20+@{cn|DEX_mod}]]|Constitution,CON Modifier}} {{roll=[[1d20+@{cn|CON_mod}]]|Intelligence,INT Modifier}} {{roll=[[1d20+@{cn|INT_mod}]]|Wisdom,WIS Modifier}} {{roll=[[1d20+@{cn|WIS_mod}]]|Charisma,CHA Modifier}} {{roll=[[1d20+@{cn|CHA_mod}]]} }} Thank you! That's neat, how the query result writes in the whole rest of the macro -- and it seems like a powerful option, I could essentially have very different output based on query input. Anyway, using your example of having the query output the remainder of the macro, I found a way to make this work (thanks for the tip about HTML replacements for offending characters!) and that combined with nesting a macro in a roll query has allowed me to completely accomplish the more complicated thing I was trying to do. Thanks so much!
1575889949

Edited 1575890065
Ziechael
Forum Champion
Sheet Author
API Scripter
You are most welcome, it's a slippery slope with many pitfalls but for those of us who make it to the top of that particular learning curve the view is incredible! When writing queries it is good practice to keep as much of the static content as possible outside of the query, the less you have to nest, the better. As a hint for numerical value based single query macros: Binary is key... I tend to set most of my things to simple yes/no queries with 1/0 outputs. That way I can use the same query call multiple times throughout but alter the output with math. Helpful for things that give a -5 to attack but +10 to damage etc. Another top tip is query ordering ... but thats more niche :) Happy query nesting!