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

Storing dice output to a temp attribute...

Greetings...I am rolling an idea around in my head as a general concept at this stage and am looking for feedback and input from the coding geniuses on this site. I want to be able to store the output value of a dice roll so that it can be used more than once in a macro. What I am thinking is this.... If I create a dummy character sheet with an attribute called "dice" could I use an API such as "tokenmod" to change the value of "dice" and then call that value from my macro so that I can use it in multiple calculations? Any thoughts appreciated....
1567223738

Edited 1567224063
GiGs
Pro
Sheet Author
API Scripter
If you wish to reuse roll results within the same roll, i think the only way to do it is to write a custom script to do it. I've posted several examples of such scripts to the forums, but each one has to be written for the specific game it's being used for - there's no standard way to do it. If you want to store the result of dice, and then all it in a later macro, you can probably do that with the method you suggest - chatsetattr might be better than tokenmod for this purpose. If you want to reuse the roll within the same macro, you need a custom script - chatsetattr and tokenmod wont work: Because of the order of events and async processing, the value you want wont be available at the right time. Any attribute calls are done at the start, when the macro is being loaded: saving a value into the attribute can't happen in time to be used in the same macro. The sequence would go like this (I've simplified a bit, for the purpose of explanation): roll20 starts up the macro, checks all atttribute calls in the macro and replaces any references to them in the macro with their values Your macro rolls its dice, and tells chatsatattr to save that roll in a a dice result attribute. The saving doesnt happen yet. You attempt to use dice result attribute in another place in the macro. The macro uses the value from step 1, not step 2. The macro ends, and the dice result attribute is updated the with value you sent it, and can be used in later macros. So when you try to use the dice result, it isn't actually available - it gets the value you stored in it last time you ran the macro.
GiGs said: If you wish to reuse roll results within the same roll, i think the only way to do it is to write a custom script to do it. I've posted several examples of such scripts to the forums, but each one has to be written for the specific game it's being used for - there's no standard way to do it. If you want to store the result of dice, and then all it in a later macro, you can probably do that with the method you suggest - chatsetattr might be better than tokenmod for this purpose. If you want to reuse the roll within the same macro, you need a custom script - chatsetattr and tokenmod wont work: Because of the order of events and async processing, the value you want wont be available at the right time. Any attribute calls are done at the start, when the macro is being loaded: saving a value into the attribute can't happen in time to be used in the same macro. The sequence would go like this (I've simplified a bit, for the purpose of explanation): roll20 starts up the macro, checks all atttribute calls in the macro and replaces any references to them in the macro with their values Your macro rolls its dice, and tells chatsatattr to save that roll in a a dice result attribute. The saving doesnt happen yet. You attempt to use dice result attribute in another place in the macro. The macro uses the value from step 1, not step 2. The macro ends, and the dice result attribute is updated the with value you sent it, and can be used in later macros. So when you try to use the dice result, it isn't actually available - it gets the value you stored in it last time you ran the macro. Cheers GiGs...understood... Using the Hero system rules as I am, I need to calculate BODY and STUN damage from the same dice roll, so this is a problem I would like to overcome. I am currently generating the roll and then adding text in the chat window to remind players to "calculate the stun" or "add up the body"...it works, but it's not very elegant and makes the messages in the chat window much larger and less efficient than I would like... I will most likely go the the script idea at some stage... Thanks  :)
1567237696
GiGs
Pro
Sheet Author
API Scripter
If you dont mind using a script, i already have one for this:  HERO System Damage Roller It'll calculate body and stun, and if you want them, knockdown or knockback, and/or hit location (using any of the legal hit location rolls in hero system, calculating appropriate body and stun), and handles the killing damage difference between 6e and earlier editions.
GiGs said: If you dont mind using a script, i already have one for this:  HERO System Damage Roller It'll calculate body and stun, and if you want them, knockdown or knockback, and/or hit location (using any of the legal hit location rolls in hero system, calculating appropriate body and stun), and handles the killing damage difference between 6e and earlier editions. Thanks GiGs...I'll take a look at it...  :)