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

How to Select Dice Displayed In Chat and Reroll Them?

1538000696

Edited 1538023194
I'm currently working on programming a dice roller for Vampire: the Masquerade 5th Edition.  In the game system, you can spend willpower to reroll up to three dice in a roll. The way my dice roller works, is that it outputs images of each die rolled and then computes the results.  I would like to make it possible for players to click on dice they wish to reroll, highlighting them, and then click a button at the bottom which would output a new roll with the selected dice rerolled. I think I know how to do the highlighting bit (assuming I can use the checkbox/span::before CSS trick commonly used in character sheets in chat), and I know I can create a button that sends an API command.  How can I set up the API command so that it knows which dice have been selected?  For example, if six dice are rolled, and the player selects the third die and the fifth die, I'd like the reroll button to send an API command like "!reroll {original roll results} 35". Alternatively, if that isn't possible, perhaps I could make every die that's displayed be a button, and have each one send an API command like "!select {die number}" or "!deselect {die number}" in a way that changes an attribute, so that when the final "!reroll" button is clicked, the API just looks up the attribute in which the selected dice numbers are stored, and rerolls those?  If I do this, how can I make the dice buttons work as a toggle that changes their appearance (with a highlight or something) when they're selected? (I'm not using roll templates for this, choosing instead to send raw HTML from the initial !roll API --- I just find it easier) Any help would be much appreciated! EDIT:  Another method to dynamically change the results of already-entered chat commands just occurred to me, in case limitations preclude the options I suggested above.  Would it be possible to use positioning cheats to overlay a newly-generated chat message directly on top of a previous one?  For example, if my first message is contained like this: <div style="height: 200px; z-index: 0;"> ... </div> And a message to immediately follow it is styled like this: <div style="height: 200px; margin-top: -200px; z-index: 1;"> ... </div> Would the second message cover up the first message, allowing for the appearance of dynamically-changing chat messages?  (I'm at work and can't test right now, but thought I'd post the idea in case it helps with responses in the meantime!) This would let me just generate an entire new roll results div for each time a die is selected, with the only difference being a highlight around the selected die, and the command for the final api "reroll" button being changed to reflect the selected numbers (I'd just have to increment the z-index by one each time, yes?)
1538008503
GiGs
Pro
Sheet Author
API Scripter
You cant really do it exactly  the way you want to. The way my dice roller works, is that it outputs images of each die rolled and then computes the results.  I would like to make it possible for players to click on dice they wish to reroll, highlighting them, and then click a button at the bottom which would output a new roll with the selected dice rerolled. When sending output to chat, you can embed a hyperlink, which can be another macro call. But you cant change the state (click a die to check it before making a reroll). You could do it this way: Have a hyperlink attached to each die, and underneath the die display the reroll button. When you click a die's hyperlink, it prints out the entire dice result again, with this particular die greyed out or replaced with a reroll symbol or whatever. It also modifiers the hyperlink linked to the reroll button. Do that as many times as you need to get the dice you want checked, and when ready, click the reroll button, and it will print everyything out one more time, rerolling the selected dice. Constructing the various hyperlink texts will be pretty tricky, but it is doable. It's going to lead to a very cluttered chat display though.
1538009049
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
As a totally different way to handle this, there is this Stupid Trick . Not exactly what you were looking for, but I thought I'd throw it out there.
1538010800
GiGs
Pro
Sheet Author
API Scripter
That's a much simpler way to do it!
1538018245
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
There's a lot you could do to automate it with things like Token-Mod to roll faces or mark dice by changing their tints, or Token-lock to keep them in a segregated area of the table.
1538023402

Edited 1538023428
Actually, it looks like the solution I edited into my first post does work! ... my first message is contained like this: <div style="height: 200px; z-index: 0;"> ... </div> And a message to immediately follow it is styled like this: <div style="height: 200px; margin-top: -200px; z-index: 1;"> ... </div> ... the second message does cover up the first message --- so I can simply make any click to any button on the message trigger a new chat message that overlays itself on top of the old one, replacing all of the buttons and graphics with whatever I like. It strikes me that this is quite a powerful trick for dynamic interaction with roll results; I'll play with it a bit more and post once I understand the ins and outs of it.  (One thing I'll need to look into is locking the chat frame to player input while a roll is "live" --- because if someone posts something to chat in between subsequent overlays, it'll mess up the vertical positioning.)
1538050627
GiGs
Pro
Sheet Author
API Scripter
Intriguing. How does this approach work in the following case: You print out your dice roll to chat. Other people send ordinary messages to chat, "I visit the inn", "I backhand the gnome for his insolence", "I attack the darkness", etc. Then  you click the dice to check decide which to reroll, and reroll them? Where does the new chat overlay appear in the time line? Does the new dice result block appear over the old roll result, up on the timeline, before the chat messages that have occurred since then? If it does work this way, it's neat, but it leads to potential confusion if you are messing around with the timeline of chat, and it could easily vanish off the top of the screen as people continue to chat, even before the final result is determined, causing people to have to scroll back to see it.
1538055031

Edited 1538055451
Actually, after experimenting with it a bit, I decided to post a new topic discussing this solution.  The problem of people chatting in between overlays needing to go up is the #1 issue to deal with, but I'm experimenting with a few ways to address it.  Other than that, however, it really does work quite well.  (And depending on how frequently players use chat --- which, in my games, isn't frequent --- it might even be possible to largely do away with this issue by just telling people not to type when someone is rolling... perhaps with a red warning down at the bottom or something.) The full thread includes a simple API script that's really easy to plug-and-play, if you want to see how it works for yourself:  Otherwise, here's the bit where I discuss the problem you raised: Some Issues: If another player types something, or any other chat message comes through, the relative positioning of the overlays will obviously fail.  A few things I'm considering (all of which treat the interrupting chat messages as things to be discarded, on the theory that they can resubmit once the "roll-in-progress" is finished resolving): Activating an on("chat: message") event during the time that a script is in between overlays, which adds negative spacers to the bottoms of incoming messages in an attempt to shunt things back into the proper position. Looking into ways to temporarily block all chat messages (or "font-size: 0", or something) during those periods between overlays. Trying to track the number of lines of text that's come through, derive the vertical pixel shift from that, and updating the margin-top value of the overlay to compensate. Responding immediately to any chat message by reposting the overlay block in its current state, so that it is always positioned as the most-recent message in the chat log. As a last resort, simply including a big red "ROLL IN PROGRESS; DO NOT SUBMIT TO CHAT" warning at the bottom.  This would certainly work in my group (we use voice chat and know each other fairly well), but I'd still like to find something a bit more robust. Every five or so posts, the ID of the poster (blank, in the case of this script) is prepended to the post.  This changes the height, and causes the previous overlay to creep up about 15 pixels.  This only affects a small strip of previous overlay becoming visible at the top, however (the positions of all of your updated elements remain fixed), so I'm thinking designing an ambiguous/fuzzy top edge to mask this flaw will be plenty good enough for me.
1538055467
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
You might want to experiment cautiously with this one while working it out. The chat log can easily be compromised and require deletion to restore functionality to a game.
Thank you very much for the warning!  I'll keep that in mind.  Just to be clear, the only risk would be the contents of the chat, and if I clear the chat log from the Settings drop-down on the Launch page, that should solve any problems?
1538058059

Edited 1538058121
GiGs
Pro
Sheet Author
API Scripter
Oh yeah, Keith is right. When the chat log gets corrupted, it makes the campaign completely unusable until you delete the entire chat history, so it is a very risky thing to play with. Yes, clearing the history from the Launch page Settings is the usual fix for issues of this nature. Note that chat corruption can present itself in different ways-  sometimes chat can still display, but macros and rolls stop working, for instance.