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

Help with Custom Roll Parsing

1696797904
Jiboux
Pro
Sheet Author
Compendium Curator
Hello all, I have up to now not developped anything regarding rolltemplate, chat menus, or macros, so I am still a bit struggling understanding the syntax... My ultimate goal is to transfer from API to the sheetworker a feature to track the expenses of XP (called LP in Earthdawn). On change of the value of a certain attributes, the current API function sends a chat proposing to the player to record the expense of LP (Earthdawn equivalent of XP). We were using API, because it seemed the only way to have some kind of button appearing in the chat following an event, until CRP. I have been tinkering with the example given on the Wiki, and stealing stuff from various posts, but have still a lot of confusion. Below the ressources used <a href="https://wiki.roll20.net/Button#Roll_Parsing" rel="nofollow">https://wiki.roll20.net/Button#Roll_Parsing</a> &nbsp;(gave me the basic structure) <a href="https://app.roll20.net/forum/post/10375623/slug%7D" rel="nofollow">https://app.roll20.net/forum/post/10375623/slug%7D</a> &nbsp;(Gave me the syntax to pass one of the JS variables to the template, even though I still don't understand why I have to use&nbsp; ` and not ' or " <a href="https://app.roll20.net/forum/post/10346883/adventures-with-startroll" rel="nofollow">https://app.roll20.net/forum/post/10346883/adventures-with-startroll</a> &nbsp;( I haven't finished understanding the very detailed post by Oosh, I still need to dig into it, but I stole already the syntax for the buttons) Detect value &lt;input type="number" name="attr_testvalue" value="0"&gt; &lt;!-- The value that triggers the event--&gt; Value to be updated &lt;input type="number" name="attr_testvalue2" value="0"&gt; &lt;!--The value that will record the costs --&gt; &lt;button type="action" name="act_update"&gt;Update&lt;/button&gt; &lt;!--A test button to trigger the update, should be hidden--&gt; &lt;rolltemplate class="sheet-rolltemplate-test"&gt; &lt;div class="sheet-template-container"&gt; &lt;h1&gt;{{name}}&lt;/h1&gt; &lt;div class="sheet-results"&gt; &lt;div&gt; Changed value from {{previousVal}} to {{newVal}} &lt;br&gt; Cost is {{cost}} &lt;h4&gt;[{{buttonlabel}}](~Test3|{{buttonlink}}||{{computed::passthroughdata}})&lt;/h4&gt; &lt;!-- I stole the syntax from Oosh, but I have hardcoded the character, and don't know how to deal with the passthrough--&gt; &lt;/div&gt; &lt;/div&gt; &lt;/rolltemplate&gt; &lt;script type="text/worker"&gt; on('change:testvalue', (info) =&gt; { log("info " +JSON.stringify(info)) let newVal=parseInt(info.newValue)|0, previousVal=parseInt(info.previousValue)|0, cost=(newVal-previousVal)*100; startRoll(`&amp;{template:test} {{name=Test}} {{newVal=${newVal}}} {{previousVal=${previousVal}}} {{cost=${cost}}} {{buttonlabel=Click to Update}} {{buttonlink=update}} {{passthroughdata=[[0]]}}`, (results) =&gt; { // //Parts that were in example that I don't use // {{roll1=[[1d20]]}} // const total = results.results.roll1.result // const computed = total % 4; // // finishRoll( // // results.rollId, // // { // // roll1: computed, // // } // ); }); }); on('clicked:update', (info) =&gt; { // Currently only incremeenting by one, but would like to increment by cost log("Update " +JSON.stringify(info)); getAttrs(["testvalue2"], function(values) { let vals={}; vals["testvalue2"]=(parseInt(values["testvalue2"])||0)+1; setAttrs(vals); }); }); &lt;/script&gt; Here are some of the questions I still can't find the answer: I read somewhere that if the button clicked on the template was related to the same character, the character name or id were optional... But currently the only way I found to have the button work is to hardcode the character name "Test3". I &nbsp;don't know how to actually get the character name or id (even if worse case I could read it via a gettAttrs, but it feels not the correct answer In the code I stole from Oosh, there is this "passthroughdata", and indeed currently in the update function I just increment by 1 the value to be updated, but in fact I would like to increment it by "cost"... But I don't understand yet how to pass data Because I only use the CRP to actually be able to send a button to the chat, I didn't actually specify a roll or anything with finishroll and the roll result... But there is still a certain lag between the change of testvalue, and the fisplay in the chat... Is there a different strategy / structure I could use After the user has clicked on "Click to Update", I'd like to send to chat something like "Update done, new Value is ${testvalue2} "... Is there any other way to send this feedback to the chat (apart from another CRP ? ) Thanks all for the guidance... I may be completely misusing the CRP and do it completely different... It s just the only function I have seen from Sheetworker that to my understanding allows a button to be sent to the chat...
1696815113
GiGs
Pro
Sheet Author
API Scripter
The lag your seeing is probably because y7ou have finishRoll commented out. With no fiishRoll function, the code waits 5 seconds to see if there is on. With a finishRoll funcvtion, it acts almost instantly. I may be completely misusing the CRP and do it completely different... It s just the only function I have seen from Sheetworker that to my understanding allows a button to be sent to the chat... No, you are correct here. CRP is the only way to do this. I'm not sure why you need the character id. Can you explain that? Can you give an example of how you'd want to use it? even though I still don't understand why I have to use&nbsp; ` and not ' or " This symbol, `, is called the backtick, and is used in something called a template literal, or string literal. It is a special kind of string that allows code within it. For example: ${newVal}. It is different from the normal quotes. Anything inside ${ } is processed as a javascript block, and is not a string. So, in this instance, it allows you to include the newVal variable. If you were doing this with a normal string, you'd type startRoll("&amp;{template:test} {{name=Test}} {{newVal=" + newVal + "}} (and so on)") backticks and template literals allow you to write strings in a different way, and are more flexible and comfortable once you are familiar with them. I don't know how you want to use passthrudata, but you could, for example, do this: startRoll(`&amp;{template:test} {{name=Test}} {{newVal=${newVal}}} {{previousVal=${previousVal}}} {{cost=${cost}}} {{buttonlabel=Click to Update}} {{buttonlink=update}} {{passthroughdata=[[0]]}}`, (results) =&gt; { // const passthru = 4; finishRoll( results.rollId, { passthroughdata: passthru, } ); }); Then you could access it in your rolltemplate using computed::passthroughdata After the user has clicked on "Click to Update", I'd like to send to chat something like "Update done, new Value is ${testvalue2} "... Is there any other way to send this feedback to the chat (apart from another CRP ? ) If you just want to send text to chat, and do nothing else, you can use a roll button. If you are changing an attribute at the same time, you have to use another CRP.
1696822411
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
I would strongly &nbsp;recommend that you not have a chat message happen based on an attribute change. It would be incredibly easy for a user to wind up spamming their game's chat with messages asking them to confirm a level up. For the use case that you are proposing, I would recommend setting up a display next to the skill level that shows the xp required to do the level change. And add an action button next to the xp display to use that xp. I'll note though, that really you're going to want a display of the current level and an input for the new level. Then have the xp deducted, the current level updated, and the new level cleared when the user clicks on the action button to apply the change.
1696859502
Jiboux
Pro
Sheet Author
Compendium Curator
Thanks Gig for the great clarifications: The lag your seeing is probably because y7ou have finishRoll commented out. With no fiishRoll function, the code waits 5 seconds to see if there is on. With a finishRoll funcvtion, it acts almost instantly. I uncommented, and still have the 5 seconds lag. I'm not sure why you need the character id. Can you explain that? Can you give an example of how you'd want to use it? Well, the functionality is that if a player levels one of his abilities on the sheet, a dialog appears on the chat with a button to update his number of XPs. The button has of course to be related to the character (you don't want a change of level of character A changing the XP of character B). Currently I have hardcoded the name of a test character, but I will need to be able to read the actual character name or id
1696859746
Jiboux
Pro
Sheet Author
Compendium Curator
I would strongly &nbsp;recommend that you not have a chat message happen based on an attribute change. It would be incredibly easy for a user to wind up spamming their game's chat with messages asking them to confirm a level up. For the use case that you are proposing, I would recommend setting up a display next to the skill level that shows the xp required to do the level change. And add an action button next to the xp display to use that xp. I'll note though, that really you're going to want a display of the current level and an input for the new level. Then have the xp deducted, the current level updated, and the new level cleared when the user clicks on the action button to apply the change. We are currently doing this exact functionality through the API... there were some tweaks with it (including making sure it is whispered only to the player and the GM, and making sure it can't be triggered by version updates), but overall no spamming occured... The other suggestions you made, I'd have to think, this could be a different approach.
1696872088
GiGs
Pro
Sheet Author
API Scripter
Jiboux said: Thanks Gig for the great clarifications: The lag your seeing is probably because y7ou have finishRoll commented out. With no fiishRoll function, the code waits 5 seconds to see if there is on. With a finishRoll funcvtion, it acts almost instantly. I uncommented, and still have the 5 seconds lag. Can you post what the new worker looks like? Jiboux said: I'm not sure why you need the character id. Can you explain that? Can you give an example of how you'd want to use it? Well, the functionality is that if a player levels one of his abilities on the sheet, a dialog appears on the chat with a button to update his number of XPs. The button has of course to be related to the character (you don't want a change of level of character A changing the XP of character B). Currently I have hardcoded the name of a test character, but I will need to be able to read the actual character name or id You can get the character name in your sheet worker (atrubute is character_name), and construct a string that includes it, then pass that to the button you send to chat.
1696872152
GiGs
Pro
Sheet Author
API Scripter
Scott C. said: I would strongly &nbsp;recommend that you not have a chat message happen based on an attribute change. It would be incredibly easy for a user to wind up spamming their game's chat with messages asking them to confirm a level up. My impression was that a separate button would be being pressed, and then the message sent. I agrewe, it's not usually a good idea to link this to an attribute change trigger.
1696872289
Jiboux
Pro
Sheet Author
Compendium Curator
Well, based on the comment of Scott C, I have completely changed my approach, so letting the CRP for now... Instead, I have created a queue of transactions to be posted as a new repeating_section... Much cleaner and simpler...