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

Is there a way to actualy dispaly a rollresult that has been sent back via a sendChat callback?

1438170583
Chris D.
Pro
Sheet Author
API Scripter
Compendium Curator
API:sendChat says You can also add a third parameter consisting of a callback function which will be passed the results of the sendChat() call instead of sending the commands to the game. The results of the sendChat command will be an ARRAY of operations, and each individual object will be just like an object you receive during a chat:message event (see above). You can use this, for example, to perform a roll using the Roll20 roll engine, then get the results of the roll immediately. You could then perform additional modifications to the roll before sending it to the players in the game. It says you can send the results on to the players, but I can't figure out how to do it! I am playing Earthdawn, and have an api script that accepts a step number and a target number. It translates the step number into dice, and uses sendChat to send them to be rolled. The results come back via a callback to be compared against the target number. What I want to do is take the result of the roll, display it just exactly like it normally does if I had not used a callback, but then add something such as "you succeeded" or "you failed". I have tried using sendChat to resend ops, opsp0[, ops[0].content, and Rollresult, but they all result in ether an error or gibberish. Is there something else I should be sending? I have come up with two workarounds, one is to not display the individual dice rolls with their fancy dice backgrounds, etc. and just say something like "you rolled a 15 and succeeded with one extra success" or "You rolled a 4 and Failed". This is not really what I wanted to do, but it is easy and it works. The other idea I have is to not have the roll come back via a callback, but have them just display as normal, but have my script monitoring for rollresults and when it sees a roll that looks right, compare it against the target number that it has been remembering. This seems clunky and a lot of work. But it seems like it ought not be this hard. Isn't there some way to simply tell it to display the rollResult exactly as it normally would if it had not been intercepted by a callback? Thanks  sendChat(msg.who, rollMsg, function( ops ) { // This is a callback function that sendChat will callback as soon as it finishes rolling the dice.   // NOTE THAT THIS IS THE START OF A CALLBACK FUNCTION log(ops[0]); var RollResult = JSON.parse(ops[0].content); log(RollResult.total); var result = RollResult.total - parseInt( textArray[4] ); // sendChat( ops[0].who, ops[0].content ); // Send the message we just intercepted to all the users. //sendChat( ops[0].who, RollResult ); sendChat( ops[0].who, "Rolled a " + RollResult.total); if( result < 0 ) { sendChat( msg.who, "FAILURE! Failed by " + (result * -1).toString() + "." ); } else if ( result < 5 ) { sendChat( msg.who, "SUCCESS!" );
1438172686
The Aaron
Pro
API Scripter
If you omit the third parameter, the message is sent to the chat panel and will be seen by everyone. Basically, the first parameter is who it will show as having said it. The second parameter is just like typing in the chat in the game. Whispers, emotes, etc all function as they would normally. sendChat('From the API','The API rolled [[1d20]]'); This will send a message to everyone with an inline 1d20 rolled. Does that help? If you are instead wanting to know how to send a message to the chat with something rust looks like an inline roll but is really generated by the API (rather than the dice engine), that's a deeper discussion.
1438179809
DK Heinrich
Marketplace Creator
Sheet Author
Can I, in theory, use this function to add a line (or more) to a macro using !powercard v.3 in the following example Things happen and a powercard says...  ...Target must make a saving throw to avoid being poisoned --- insert a 'sendchat' whisper to that player to roll the saving throw (preferably a button in chat they click).  --- that result then kicks back to the !powercard showing the result AND allowing me to use it in conditionals to list effects based on the result Currently my output tells the target to make the roll, and I click another macro that gives results based on me telling it if he was successful or not - would be great to combine the two into one.
1438180309
The Aaron
Pro
API Scripter
Technically yes, but it would require modifying power cards significantly. You could probably pass an API button to powercard which would be displayed, the clicking of which would execute another command to pass the check back to you. 
1438182331
DK Heinrich
Marketplace Creator
Sheet Author
ok, well maybe HB is feeling like a 4.0 version.. lol
1438213234
Chris D.
Pro
Sheet Author
API Scripter
Compendium Curator
If you are instead wanting to know how to send a message to the chat with something rust looks like an inline roll but is really generated by the API (rather than the dice engine), that's a deeper discussion. Kind if, I want it to display something generated by the dice engine, I just want the api engine to do some stuff and send another message immediately afterwards. I want the api to know the roll result, so that it can process it further, IE: add additional text like "you got 2 extra levels of success." In further versions of this script I will probably have it optionally automatically generating a damage roll (with the dice rolled modified by how many levels of success was achieved on the attack roll, etc.). But I also like the default dice roll display where it shows a little d12 and a d6 (or whatever) and each displays their rolled value and then a total. In short: At present, if I don't send the result to a callback I get... Chris D. (GM): rolls step 11 plus d6 for Attack , rolling d10!+d8!+d6! (3)+(6)+(4) = 13      With the (3) shaped like a little d10, etc. If I do send the roll to my callback function, I get ... Lightning Lizard: rolls step 11 plus d6 for Attack with a target number of 15. Rolled a 6 FAILURE! Failed by 9. What I don't get is the dice rolled (rolling d10!+d8!+d6!) or the individual results with the funny dice outlines. What I want is a combination of the two Chris D. (GM): rolls step 11 plus d6 for Attack , rolling d10!+d8!+d6! (3)+(6)+(4) = 13 FAILURE! Failed by 2. Now another obvious idea is just echo the .origRoll (without the "/r"), and to manually parse the RollResult to manually build the (3)+(6), Etc. line myself. However I don't know how to do that nifty dice shaped thing underneath the number. I suppose I could live without the shapes,  but if it's not to much trouble I would like to include it. So maybe my question breaks down to: (a) Is there an easy way to tell it to just display a rollresult to everybody even though the rollresult got sent to the api instead of being displayed automatically? or (b) How would I add those dice shapes under the rolls, assuming I am going to be recreating the standard formatting by hand? or (c) would it just be simpler to store somewhere that I am looking for a specific rollresult and have the api scan all messages (not just api messages) until it thinks it found the right one, then parse it and process it. Thanks
1438231218
Chris D.
Pro
Sheet Author
API Scripter
Compendium Curator
Chris D. said: The other idea I have is to not have the roll come back via a callback, but have them just display as normal, but have my script monitoring for rollresults and when it sees a roll that looks right, compare it against the target number that it has been remembering. This seems clunky and a lot of work. I have read a number other posts on the forum where this is suggested as a workaround to various problems. The suggestion is to make a note of what you are looking for, then monitor all messages looking for an exact match. Can somebody point me to some sample code that does this particularly well that I might look at?