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

[LookingFor] Script to track a dice result

October 27 (4 years ago)

Hello there !

On my character sheet I'd like to have a macro like that :

" /roll 1d20

Random stat name 1 : {@Random stat name 1}+{@Dice_result}

Random stat name 2 : {@Random stat name 2}+{@Dice_result}

Random stat name 3 : {@Random stat name 3}+{@Dice_result} "


I tried to find a script to do this, but I can't find it. Can anyone help me ? Thanks a lot !

October 27 (4 years ago)

Edited October 27 (4 years ago)
GiGs
Pro
Sheet Author
API Scripter

You cant actually reuse the same roll in different operations like that.

Well, there is a way, but it's clunky and not pretty.

&{template@default} [[ [[  [[ [[1d20]] +  @{Random stat name 1} ]] - @{Random stat name 1} + @{Random stat name 2}]] -@{Random stat name 2} + @{Random stat name 3}]] {{Roll=$[[0]]}} {{Random Stat Name 1=$[[1]]}} {{Random Stat Name 2=$[[2]]}} {{Random Stat Name 3=$[[3]]}}

This uses the recently discovered Reusing Rolls trick (see the wiki for an explanation of how it works).

Also note the corrected syntax on attribute calls: the @ goes outside the curly brackets.

I'm not entirely sure what GiG's macro does but its totally possible to use a past roll with chatsetattr its just a lil convoluted and keep in mind that annoying bug with multiple api commands in a macro exists so everything has to be on seperate buttons cause apparently the devs need to redo lighting instead of make macros run multiple api commands again reliably.  

1.  Have chatsetattr make a new obscurely named attribute on the players sheet and its value be the inline roll result to later use.  

2.  When you need to take that value rolled and apply it somewhere else just call that sheets obscurely named attribute which is now that single roll instance till you run that button again.  


An example of using this method would be making a 2 button Life Transference button.  Because of the stupid multiple commands bug I think you actually need 3 buttons cause you have to do a command to make the attribute, a command to call the attribute as a modifier to hitpoints and a command to heal another player with that valuex2.  

October 27 (4 years ago)
GiGs
Pro
Sheet Author
API Scripter


DM Eddie said:

Because of the stupid multiple commands bug 

This isnt a bug, and its the way roll20 has always worked. See the wiki page on the Order of Operations: https://wiki.roll20.net/Dice_Reference#Order_of_Operations

I agree its inconvenient - I wish it didnt work this way. But it's not a bug.

October 27 (4 years ago)


GiGs said:

You cant actually reuse the same roll in different operations like that.

Well, there is a way, but it's clunky and not pretty.

&{template@default} [[ [[  [[ [[1d20]] +  @{Random stat name 1} ]] - @{Random stat name 1} + @{Random stat name 2}]] -@{Random stat name 2} + @{Random stat name 3}]] {{Roll=$[[0]]}} {{Random Stat Name 1=$[[1]]}} {{Random Stat Name 2=$[[2]]}} {{Random Stat Name 3=$[[3]]}}

This uses the recently discovered Reusing Rolls trick (see the wiki for an explanation of how it works).

Also note the corrected syntax on attribute calls: the @ goes outside the curly brackets.

Thank you ! I tried it but as you said, it's very clunky, and unfortunately doesn't work for me.

I tried to have :

Line 1 : /r 1d20

Line 2 : {{Roll=$[[0]]}} + @{attribute}

But looks like I can't add anything to the number from the command $[[0]] ...


DM Eddie said:

I'm not entirely sure what GiG's macro does but its totally possible to use a past roll with chatsetattr its just a lil convoluted and keep in mind that annoying bug with multiple api commands in a macro exists so everything has to be on seperate buttons cause apparently the devs need to redo lighting instead of make macros run multiple api commands again reliably.  

1.  Have chatsetattr make a new obscurely named attribute on the players sheet and its value be the inline roll result to later use.  

2.  When you need to take that value rolled and apply it somewhere else just call that sheets obscurely named attribute which is now that single roll instance till you run that button again.  

An example of using this method would be making a 2 button Life Transference button.  Because of the stupid multiple commands bug I think you actually need 3 buttons cause you have to do a command to make the attribute, a command to call the attribute as a modifier to hitpoints and a command to heal another player with that valuex2.  

So it is not possible to set an attribute with Chatsetattr, and to track it in the line below on the same macro ? It would require at least 2 or 3 clics ?

October 27 (4 years ago)

Edited October 27 (4 years ago)
GiGs
Pro
Sheet Author
API Scripter


Ledouaje said:

Thank you ! I tried it but as you said, it's very clunky, and unfortunately doesn't work for me.

I tried to have :

Line 1 : /r 1d20

Line 2 : {{Roll=$[[0]]}} + @{attribute}

But looks like I can't add anything to the number from the command $[[0]] ...

This is correct. The special $[[0]] entities are not numbers, and you cannot add anything to them.

My code had a typo: the start should have been &{template:default} not &{template@default}

If you enter the attribute names properly, the code will work with that fix.


Ledouaje said:

So it is not possible to set an attribute with Chatsetattr, and to track it in the line below on the same macro ? It would require at least 2 or 3 clics ?

This is correct, and is because of the order of operations I linked in my last post.

When you launch a macro, roll20 calls all attributes mentioned in the macro, and uses their values as they are at the start of the macro for the entire macro. Any changes you make to stats during that macro dont have any effect until after the macro ends.

October 27 (4 years ago)
GiGs
Pro
Sheet Author
API Scripter

To illustrate the Reusing Rolls method. Imagine you have 3 stats, STR, DEX, and CON, and wanted to roll a d20 and add it to all these. That would lok like this:

&{template:default} [[ [[ [[ [[1d20]] + @{STR} ]] - @{STR} + @{DEX}]] -@{DEX} + @{CON}]] {{Roll=$[[0]]}} {{STR=$[[1]]}} {{DEX=$[[2]]}} {{CON=$[[3]]}}
October 28 (4 years ago)

Now it's working ! Thanks a lot !

November 12 (4 years ago)

Edited November 12 (4 years ago)


GiGs said:

To illustrate the Reusing Rolls method. Imagine you have 3 stats, STR, DEX, and CON, and wanted to roll a d20 and add it to all these. That would lok like this:

&{template:default} [[ [[ [[ [[1d20]] + @{STR} ]] - @{STR} + @{DEX}]] -@{DEX} + @{CON}]] {{Roll=$[[0]]}} {{STR=$[[1]]}} {{DEX=$[[2]]}} {{CON=$[[3]]}}

Hello it's me again

I have issue with this method with attributes lower than 0, like " -1 ". They disturb every result following their. Do you think something can be made in the code to fix this ?


[[1d20]] + @{STR} ]] - @{STR} + @{DEX}]]


Let's say STR = -1 and DEX = 5


 The  " - @{STR} part " doesn't change the -1 into a +1 like I thought it would, and make everything bug..


I tried to do something like this :

[[1d20]] + @{STR} ]] - [[@{STR} + @{DEX}]] ]] -[[@{DEX} + @{CON}]] ]] (etc)


But it absolutely doesn't work. Can you help me again ? :(

Even if it needs an API script, I'm open to all solutions.

November 12 (4 years ago)
GiGs
Pro
Sheet Author
API Scripter

Try putting ( ) around each attribute, like

[[ [[ [[ [[1d20]] + (@{STR}) ]] - (@{STR}) + (@{DEX})]] -(@{DEX}) + (@{CON})]] 


November 12 (4 years ago)


GiGs said:

Try putting ( ) around each attribute, like

[[ [[ [[ [[1d20]] + (@{STR}) ]] - (@{STR}) + (@{DEX})]] -(@{DEX}) + (@{CON})]] 



THANK YOU SIR THANKS A LOT !

November 12 (4 years ago)
GiGs
Pro
Sheet Author
API Scripter

hehe, you're welcome.

November 13 (4 years ago)
timmaugh
Forum Champion
API Scripter

I know people get tired of me saying this but there is a way to do this with InsertArg, I think.

1) build a template of the ability with 'hooks' in the place of the roll you want to drop; we'll call it SOURCE:

Random stat name 1 : [[@{Random stat name 1}+roll1hook]]
Random stat name 2 : [[@{Random stat name 2}+roll1hook]]
Random stat name 3 : [[@{Random stat name 3}+roll1hook]]

2) have a designated target for the finished command line; we'll call that TARGET (this step might be unnecessary, depending on the macro you are altering)

3) run an IA command something like...

!ia --button#SOURCE --roll1hook#[[1d20]] --label#Random Stat Macro

That will alter the command line from the SOURCE template, filling in the same roll to several locations, and drop a button into the chat. The button will run the altered command line. Instead of "button" you can use "chat" to run the altered command line immediately, or you can use "load" and then supply the TARGET as the destination if you want to store the result into the TARGET ability. The TARGET will be overwritten everytime you run the IA command, utilizing the SOURCE command line and handling the replacements. To supply TARGET, you would give it to the "store" argument:

--store#TARGET

Anyway, it's another option. Anyone wants to try it, I'll lend a hand with the syntax and setup.

I know. I know. InsertArg is my stapler.


November 13 (4 years ago)
GiGs
Pro
Sheet Author
API Scripter

Of course that's only available to games with a pro subscription. Ledouaje is Plus, which is why we havent been suggesting script solutions.

November 13 (4 years ago)
Oosh
Sheet Author
API Scripter

Which subscription comes with Milton's stapler?

November 13 (4 years ago)
Pat
Pro
API Scripter


Oosh said:

Which subscription comes with Milton's stapler?


Kickstarter reward.

November 13 (4 years ago)
GiGs
Pro
Sheet Author
API Scripter


GiGs said:

Of course that's only available to games with a pro subscription. Ledouaje is Plus, which is why we havent been suggesting script solutions.


Though maybe I misspoke. The thread title does ask for a script, so maybe we should have been offering API solutions!

November 13 (4 years ago)
timmaugh
Forum Champion
API Scripter

Yeah, I guess I hadn't noticed he was only Plus, not Pro, and was going off of the script reference... but to your point, a lot of people say "macro" when they mean "ability" and "script" when they mean "sheetworker" or "code I need to put on my sheet," so Ledouaje was still probably looking for a plus-level solution.

Still, as you say, there are script solutions, too, if people find this thread later. Cheers!