Chat Menu Variables Trick
I've been working on a trick to pass variables (rolls) stored in Chat Menu Buttons. I will update once it becomes more refined. However, this is the first implementation. This relies on integrating several other tricks like the re-use rolls trick ($[[0]]), various math tricks allowing re-use of rolls one time in a math roll or other roll, text and button formatting tricks, and copious amounts of HTML replacements to make sections evaluate at specific points in the order of operations. In the sections below, I have underlined the text that needs to be replaced for your convenience.
Basic Single variable implementation
No Roll Template Button with printed variable
Here is the button that you place inside your main macro or ability that produces the variables to pass along. Note that there can be no line breaks.
[[5+5]] [BUTTON](`%{selected|ABILITY} {{[[[$[[0]]]]]}}" style="border:1px solid white;background-color:rgb(206, 15, 105);padding:5px;color:white;display:inline-block;)
Here is the basic format required for the ability to use the stored variable. Note that you will have to increment $[[0]] by 1 for every normal roll that doesn't call a variable within the ability. A rule of thumb is, +1 for every use of "]]" not containing $[[#]]. Determining variable indexing gets a bit more complicated when you implement multiple variables.
&{template:default} {{name=ABILITY}} {{1 if variable is greater than 5:= [[ ceil( ( $[[0]]-5 )/10000 ) ]]}}

IMPORTANT NOTES:
- Non-math only rolls involving 1d20 or other dice rolls print Rolling before the value in hidden text. This will break the trick unless you nest non-math only rolls inside of something like a keep high roll such as [[ { [[1d20]] , [[0]] }kh1 ]]. This will make the desired roll index to store $[[2]] instead of $[[0]].
- Without using a roll template containing the button, all rolls must be on the "same line" as the button or the indexing will reset betwen the roll and printing the button. The %newline% trick can be used for formatting if using the button without a roll template.
- The roll template in the ability is not strictly required unless you want to be able to hide the variables by removing the braces around the variable in the button.
- You can replace selected inside the button with a target or with a reference to a "macro mule" or replace the ability %{selected|ABILITY} all together with a macro #ABILITY if you don't want to use the selected token's ability. Don't forget the space after ABILITY if you do this
Roll Template Button with printed variable
Here is the button that you place inside your main macro or ability that produces the variables to pass along. This time, using a roll template
&{template:default} {{name=Chat Menu Variables Trick}} {{Variable A:=[[3+1]]}} {{Chat Menu:=[BUTTON](`%{selected|ABILITY} {{[[[$[[0]]]]]}}" style="border:1px solid white;background-color:rgb(206, 15, 105);padding:5px;color:white;display:inline-block;)}}
Here is the basic format required for the ability to use the stored variable. Note that you will have to increment $[[0]] by 1 for every normal roll that doesn't call a variable within the ability. A rule of thumb is, +1 for every use of "]]" not containing $[[#]]. Determining variable indexing gets a bit more complicated when you implement multiple variables.
&{template:default} {{name=ABILITY}} {{1 if variable is greater than 5:= [[ ceil( ( $[[0]]-5 )/10000 ) ]]}}

Roll Template Button with invisible variable
Here is the button that you place inside your main macro or ability that produces the variables to pass along. This time, without braces around the variable in the button to make the passed through variables not print when the ability uses a roll template.
&{template:default} {{name=Chat Menu Variables Trick}} {{Variable A:=[[3+1]]}} {{Chat Menu:=[BUTTON](`%{selected|ABILITY} [[[$[[0]]]]]" style="border:1px solid white;background-color:rgb(206, 15, 105);padding:5px;color:white;display:inline-block;)}}
Here is the basic format required for the ability to use the stored variable. Note that you will have to increment $[[0]] by 1 for every normal roll that doesn't call a variable within the ability. A rule of thumb is, +1 for every use of "]]" not containing $[[#]]. Determining variable indexing gets a bit more complicated when you implement multiple variables.
&{template:default} {{name=ABILITY}} {{1 if variable is greater than 5:= [[ ceil( ( $[[0]]-5 )/10000 ) ]]}}

Single variable implementation inside Query
With template, printed variables
When placed inside a query, the HTML replacements become a little complicated for the first nesting. This is because the query itself requires different replacements than the button. After the first time, you just add amp; after every & as normal. Here is the button nested inside a random query
&{template:default} {{name=Chat Menu Variables Trick}} {{Variable 1:=[[1+2]]}} {{Variable 2:=[[3+4]]}} ?{Do you want to pass Variable 1 or Variable 2 through to the next ability button?|
Variable 1,{{Ability Menu: =[BUTTON](`%{selected|ABILITY} {{[[[$[[0]]]]]}}" style="border:1px solid white;background-color:rgb(206, 15, 105);padding:5px;color:white;display:inline-block;)}}|
Variable 2,{{Ability Menu: =[BUTTON](`%{selected|ABILITY} {{[[[$[[1]]]]]}}" style="border:1px solid white;background-color:rgb(206, 15, 105);padding:5px;color:white;display:inline-block;)}}}
Here is the basic format required for the ability to use the stored variable. Note that you will have to increment $[[0]] by 1 for every normal roll that doesn't call a variable within the ability. A rule of thumb is, +1 for every use of "]]" not containing $[[#]]. Determining variable indexing gets a bit more complicated when you implement multiple variables.
&{template:default} {{name=ABILITY}} {{1 if variable is greater than 5:= [[ ceil( ( $[[0]]-5 )/10000 ) ]]}}

I may come back at a later date to update this trick making the documentation more detailed. I am still testing the multi-variable version, which is easily possible. However, variable indexing becomes a tad complicated. I have a rudimentary version of it working that passes through 8 variables into some pretty complicated rolls in various sections of a roll template. It just doesn't translate well into a generic ability useful for cut and paste then editing.
Anyone who would like to try can just duplicate the text around the variables inside the button and play with the indexing of called variables in the ability. A word of warning, this may require passing the same variable several times if a trick to fix the indexing isn't used like surrounding the roll with a keep high roll [[ { [[ $[[1]]+0 ]] , [[0]] }kh1 ]]. That will indroduce additional rolls that will execute before the stored variable rolls though. Hence why I've bumped $[[0]] up to $[[1]] in the text.
Another nice thing I discovered is that there is no detriment to including extra variables that you don't use. So you can pass variables to abilities on tokens that are written completely differently by writing the calls to the first set of variables outside of braces at the beginning of the second ability so those variables don't print out. Then you can continue calling other variables used in the second set of abilities. The order you pass variables through a button to a new ability matters but you can bypass those limitations by passing everything twice in two different orders. The ability using the first set of variables will be completely unaffected.
You can pass the same variable to the button over and over again with no issue as well. Just keep duplicating the text around the variables with the same index. The only time duplicating an index is an issue is when you try to do math with it. Any math must be done in the first call to the variable.