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

[Question] Getting content of modifier in macro

1495182350

Edited 1495182376
Loki
Sheet Author
Hi! I've written the following three macros: /roll 2d10 + ?{modifier|0} VS difficulty: ?{difficulty|15} /roll 4d10k2 + ?{modifier|0} VS difficulty: ?{difficulty|15} /roll 2d10d1 + ?{modifier|0} VS difficulty: ?{difficulty|15} I'm just a beginner in terms of roll20 API. Currently I'm able to get the id's of the three macros with the help of findObj during the chat event.  But what I want is to get the value of the modifier difficulty (to calculate the amount of successes the roll represents). When I log the result of the roll I get the JSON-String with the roll results, type and dice-sides etc. But there is no information about the modifiers. So: Is there a way to get these from the chat event? Greetings, Loki
1495200669
The Aaron
Pro
API Scripter
The macro's will just have the text above, as you have discovered. When the macro is executed, it will send a chat event with the roll structure detailed here:&nbsp; <a href="https://wiki.roll20.net/API:Chat" rel="nofollow">https://wiki.roll20.net/API:Chat</a> The ?{difficulty|15} will be resolved on the client side before sending to the API, so the easiest place to get it will be the origRoll property of the message object passed to the message handler. &nbsp;Assuming no modifiers and the default value taken on the difficulty, that field will look like this: 2d10 + 0 VS difficulty: 15 You can then use string parsing techniques to get the part you want. &nbsp;In this case, you can just do: let diff = msg.origRoll.split(/\s+/).pop(); But you might want to do something more complicated depending on what you are doing with the information.
1495211413
Loki
Sheet Author
Thanks @The Aaron - it worked! I had to modify it a little bit, as you supposed. :) Greetings
1495225858
The Aaron
Pro
API Scripter
Good deal! &nbsp;Happy Rolling!