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> (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> (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 ` 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> ( 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 <input type="number" name="attr_testvalue" value="0"> <!-- The value that triggers the event-->
Value to be updated <input type="number" name="attr_testvalue2" value="0"> <!--The value that will record the costs -->
<button type="action" name="act_update">Update</button> <!--A test button to trigger the update, should be hidden-->
<rolltemplate class="sheet-rolltemplate-test">
<div class="sheet-template-container">
<h1>{{name}}</h1>
<div class="sheet-results">
<div>
Changed value from {{previousVal}} to {{newVal}} <br>
Cost is {{cost}}
<h4>[{{buttonlabel}}](~Test3|{{buttonlink}}||{{computed::passthroughdata}})</h4> <!-- I stole the syntax from Oosh, but I have hardcoded the character, and don't know how to deal with the passthrough-->
</div>
</div>
</rolltemplate>
<script type="text/worker">
on('change:testvalue', (info) => {
log("info " +JSON.stringify(info))
let newVal=parseInt(info.newValue)|0,
previousVal=parseInt(info.previousValue)|0,
cost=(newVal-previousVal)*100;
startRoll(`&{template:test} {{name=Test}} {{newVal=${newVal}}} {{previousVal=${previousVal}}} {{cost=${cost}}} {{buttonlabel=Click to Update}} {{buttonlink=update}} {{passthroughdata=[[0]]}}`, (results) => { //
//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) => { // 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);
});
});
</script> 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 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...