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

Macros: How to get different results from the same roll query name?

1463336068

Edited 1463337030
Is there any way for a single roll query name to produce different results at different points of a roll template or macro? My current formula varies by weapon, so I'll use a basic one. &{template:default} {{name=Iron Lance}} {{rank=D}} {{damage=[[{@{Str}+7-@{target|Def}+?{Triangle?|No,0|Win,1|Lose,-1}, 0}kh1+?{Modifiers|0}]]}} {{hit=[[{@{Acc}+80-@{target|Eva}+?{Triangle?}*15, 0, 100}kh2dh1]]}} {{crit=[[{@{Crt}-@{target|Lck}, 0}kh1]]}} {{range=1}} {{speed=[[@{Spd}]] vs [[@{target|Spd}]]}} The important parts to my question, made readable: {{damage=[[{@{Strength} + 7 - @{target|Defense} + ?{Weapon matchup? | Neutral, 0 | Advantage, 1 | Disadvantage,-1} , 0}kh1+?{Modifiers|0}]]}} {{hit=[[{@{Accuracy} + 80 - @{target|Evasion} + ?{Weapon matchup?}*15 , 0, 100}kh2dh1]]}} Currently, this system works. In the dumbed-down version I've been using, unit gets +1 Damage and +15 Accuracy when at an advantage, and -1 Damage and -15 Accuracy at a disadvantage. However, I want to use the proper system from the Fire Emblem games. Units can gain proficiency with weapon classes as they use them, measured in rank letters. They get bonuses to damage and accuracy based on rank, but these are nullified if they're at a weapon disadvantage. The bonuses for a lance are as follows. Rank Damage Query Accuracy Query E/D ?{Matchup? | None, 0 | Win, 0 | Lose, -1} ?{Matchup? | None, 0 | Win, 5 | Lose, -15} C ?{Matchup? | None, 1 | Win, 1 | Lose, -1} ?{Matchup? | None, 0 | Win, 10 | Lose, -15} B ?{Matchup? | None, 1 | Win, 2 | Lose, -1} ?{Matchup? | None, 5 | Win, 15 | Lose, -15} A ?{Matchup? | None, 2 | Win, 3 | Lose, -1} ?{Matchup? | None, 5 | Win, 20 | Lose, -15} S ?{Matchup? | None, 3 | Win, 5 | Lose, -1} ?{Matchup? | None, 10 | Win, 30 | Lose, -15 Now, the thing is, these queries happen twice every single time someone wants to attack; once for the attacker, once for the defender (long story); because of that, I really, really don't want to make two separate roll queries for this. Is there any possible way I could use the same roll query name for both? (Side note: Holy Christ, what is with the undo function on these forums? No, I did not want to empty the entire table, I wanted to reverse a single cell change!) EDIT: Oh, I should clarify. The macros will be manually changed when a unit ranks up; I don't need that part to be automatic.
1463345828

Edited 1463365892
Silvyre
Forum Champion
Rank Damage Accuracy E/D ?{Matchup?|None, 1|Win, 1|Lose, 0} - 1 ?{Matchup?|None, 0|Win, 1|Lose, -3} * 5 C ?{Matchup?|None, 2|Win, 2|Lose, 0} - 1 ?{Matchup?|None, 0|Win, 2|Lose, -3} * 5 B ?{Matchup?|None, 2|Win, 3|Lose, 0} - 1 ?{Matchup?|None, 1|Win, 3|Lose, -3} * 5 A ?{Matchup?|None, 3|Win, 4|Lose, 0} - 1 ?{Matchup?|None, 1|Win, 4|Lose, -3} * 5 S ?{Matchup?|None, 4|Win, 6|Lose, 0} - 1 ?{Matchup?|None, 2|Win, 6|Lose, -3} * 5 (I factored some numbers out of both Queries to get them a bit closer together.) We need to find a way to tell the macro how much we want to subtract from ?{Matchup?} to get the corresponding accuracy. My method of doing this will be adding the appropriate differences as decimal values, and then using a function to extract these values from ?{Matchup}: Rank Damage Accuracy E/D [[ floor (?{Matchup?|None, 1.01|Win, 1|Lose, 0.03}) - 1 ]] [[ (floor(?{Matchup?}) - floor((?{Matchup?} * 1e2) % (1e2 - 1e-10))) * 5 ]] C [[ floor(?{Matchup?|None, 2.02|Win, 2|Lose, 0.03}) - 1 ]] [[ (floor(?{Matchup?}) - floor((?{Matchup?} * 1e2) % (1e2 - 1e-10))) * 5 ]] B [[ floor(?{Matchup?|None, 2.01|Win, 3|Lose, 0.03}) - 1 ]] [[ (floor(?{Matchup?}) - floor((?{Matchup?} * 1e2) % (1e2 - 1e-10))) * 5 ]] A [[ floor(?{Matchup?|None, 3.02|Win, 4|Lose, 0.03}) - 1 ]] [[ (floor(?{Matchup?}) - floor((?{Matchup?} * 1e2) % (1e2 - 1e-10))) * 5 ]] S [[ floor(?{Matchup?|None, 4.02|Win, 6|Lose, 0.03}) - 1 ]] [[ (floor(?{Matchup?}) - floor((?{Matchup?} * 1e2) % (1e2 - 1e-10))) * 5 ]] The key here is that [[ floor((AB. CD * 1e2) % (1e2 - 1e-10)) ]] equals [[ CD ]]. Of course, let me know if you have any questions. ! This is a more general form of the above function/command. ! Copy and paste the entirity of this code box into the text chat of your game to see how it works. ! [AB. CD EFGHIJ] ?{Recall|AB,0| CD ,2|EF,4|GH,6|IJ,8| ... |BC,1|DE,3|FG,5|HI,7} e.g. [[ floor(floor(00.01020304 * 1e?{Recall}) % (1e2 - 1e-10)) ]] e.g. [[ floor(floor(12.34567890 * 1e?{Recall}) % (1e2 - 1e-10)) ]]
Umm... I'm sorry, I'm... really not sure what I'm looking at. How do you use this command? How do you map anything to anything?
1463369917

Edited 1463379858
Silvyre
Forum Champion
Here are the macros: Rank: E/D Damage: [[ floor(?{Matchup?|None, 1.01|Win, 1|Lose, 0.03}) - 1 ]] Accuracy: [[ (floor(?{Matchup?}) - floor((?{Matchup?} * 1e2) % (1e2 - 1e-10))) * 5 ]] Rank: C Damage: [[ floor(?{Matchup?|None, 2.02|Win, 2|Lose, 0.03}) - 1 ]] Accuracy: [[ (floor(?{Matchup?}) - floor((?{Matchup?} * 1e2) % (1e2 - 1e-10))) * 5 ]] Rank: B Damage: [[ floor(?{Matchup?|None, 2.01|Win, 3|Lose, 0.03}) - 1 ]] Accuracy: [[ (floor(?{Matchup?}) - floor((?{Matchup?} * 1e2) % (1e2 - 1e-10))) * 5 ]] Rank: A Damage: [[ floor(?{Matchup?|None, 3.02|Win, 4|Lose, 0.03}) - 1 ]] Accuracy: [[ (floor(?{Matchup?}) - floor((?{Matchup?} * 1e2) % (1e2 - 1e-10))) * 5 ]] Rank: S Damage: [[ floor(?{Matchup?|None, 4.02|Win, 6|Lose, 0.03}) - 1 ]] Accuracy: [[ (floor(?{Matchup?}) - floor((?{Matchup?} * 1e2) % (1e2 - 1e-10))) * 5 ]] And, here's a long explanation of how they work: We started with only "damage info" within ?{Matchup}. Our goal is to, somehow, acquire "accuracy info" from ?{Matchup}. In order to do so, we must first store (within ?{Matchup}) some "math instructions", which tell the macro how to acquire "accuracy info" given "damage info" (via subtraction). A mathematical function takes an input and assigns (or "maps") it to an output. In this case, our input is "damage info" and our output is "accuracy info". A convenient place to store these "math instructions" is within the decimal places of the "damage info". To make it easier to turn "damage info" into "accuracy info", I decided to try to get the "Damage Query" and "Accuracy Query" columns of your table to look as similar as possible. I actually got them to look quite similar; you'll notice that the "Win" sections in both of the columns of my first table are equal. So, as long as a unit has a "Win", we can use the Roll Queries in the first table. e.g. Copy and paste the following code into the text chat, and then reference the table in your post: This information is only correct when "Win" is chosen: Rank C Damage: [[ ?{Rank C Matchup?|None, 2|Win, 2|Lose, 0} - 1 ]] Rank C Accuracy: [[ ?{Rank C Matchup?} * 5 ]] Rank A Damage: [[ ?{Rank A Matchup?|None, 3|Win, 4|Lose, 0} - 1 ]] Rank A Accuracy: [[ ?{Rank A Matchup?} * 5 ]] We have to subtract a certain number from the "damage info" found within the "None" and "Lose" sections in order to make them output the correct "accuracy info". e.g. Take a look at the Rank E/D row of my first table. In order to acquire the Roll Query in the "Accuracy" column, we have to do the following to the Roll Query in the "Damage" column: Subtract 1 from the "None" section, or Do nothing to the "Win" section, or Subtract 3 from the "Lose" section. This is exactly what I mean by turning "damage info" into "accuracy info". This is where the "math instructions", which I've placed in the decimal places of the "damage info" sections, comes in play. e.g. Take a look at the Rank E/D row of my second table. In order to acquire the Roll Query in the "Accuracy" column, we have to do the following to the Roll Query in the "Damage" column: Subtract the "math instructions" (e.g. 1) from the "None" section, or Subtract the "math instructions" (e.g. 0) from the "Win" section, or Subtract the "math instructions" (e.g. 3) from the "Lose" section. All that's left to do is have the macro take the "math instructions" from the decimals places of the chosen output, and use that to turn the "damage info" into the "accuracy info" (via subtraction). Here's what's going on: "floor(?{Matchup?})" is the "damage info". "floor(?{Matchup?})" - "floor((?{Matchup?} * 1e2) % (1e2 - 1e-10)) % (1e2 - 1e-10))" is the subtraction of the "math instructions" from the "damage info". I wouldn't worry too much about the exact makeup of the "math instructions"; just keep in mind the following: "Rank E/D damage plus one" ([[ floor(?{Matchup?|None, 1.01|Win, 1|Lose, 0.03}) - 1 + 1 ]]) minus "Rank E/D math instructions" ([[ floor((?{Matchup?} * 1e2) % (1e2 - 1e-10)) % (1e2 - 1e-10)) ]]) equals "Rank E/D accuracy divided by 5" ([[ floor(?{Matchup?}) - floor((?{Matchup?} * 1e2) % (1e2 - 1e-10)) ]]). i.e. "Rank E/D damage" ([[ floor(?{Matchup?|None, 1.01|Win, 1|Lose, 0.03}) - 1]]) minus "Rank E/D math instructions" ([[ floor((?{Matchup?} * 1e2) % (1e2 - 1e-10)) % (1e2 - 1e-10)) ]]) multiplied by five equals "Rank E/D accuracy" ([[ (floor(?{Matchup?}) - floor((?{Matchup?} * 1e2) % (1e2 - 1e-10))) * 5 ]]).