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

[Splittermond] Custom Roll Parsing: Missing String Replacement

1631542928

Edited 1631543047
Loki
Sheet Author
Hi! I'm converting my first character sheet to Custom Roll Parsing and want to change one of the roll attributes according to the skill button that was clicked. E.g. if the player clicks on the (action) button for acrobatics, the roll template should spell 'Acrobatics' in the title. There is a trick where you can use a variable inside a roll template and fill the variable dynamically during the sheet worker. But for some reason it doesn't work for this sheet: Button: <button type="action" name="act_akrobatik" class="sheet-ability-button">0</button> Roll Template: <rolltemplate class="sheet-rolltemplate-splittermond_test"> <div class="roll-message__title"><b>rollName:</b> {{name}}</div> <div class="roll-message__subtitle"><b>Charactername:</b> {{charactername}}</div> </rolltemplate> Sheet Worker: on('clicked:akrobatik', (eventInfo) => { getAttrs(["dice_mod"], function(v) { let rollType = ""; let rollName = "Kampf"; let baseRoll = "&{template:splittermond_test} {{name=${rollName}}} {{charactername=@{character_name}}} {{Probe=[[ [[2d10]] + [[?{Modifikator|0}]] ]]}}"; switch (+v.dice_mod) { case 1: rollType = "Sicherheitswurf"; break; case 2: rollType = "Standardwurf"; break; case 3: rollType = "Risikowurf"; break; } processRoll(baseRoll); if (+v.dice_mod == 1 || +v.dice_mod == 3) { setAttrs({ dice_mod: 2 }); } }); }); processRoll(baseRoll): function processRoll(baseRoll) { startRoll(baseRoll, (results) => { let result = results.results.Probe.result; finishRoll( results.rollId, { Probe: result, } ); }); } I just created this rolltemplate for testing and AFAIK this should work. I don't see any reason why it shouldn't. Nevertheless I get this result in the chat: So, {{name}} obviously isn't replaced by "Kampf" instead the chat just prints out the whole variable name. Can anyone give me a hint where the error may be? Cheers!
1631543399
Loki
Sheet Author
Ok,.problem solved. Just for the case that someone else has this problem: It's very important that the baseRoll has the right apostrophes. let baseRoll = `&{template:splittermond_test} {{name=${rollName}}} {{charactername=@{character_name}}} {{Probe=[[ [[2d10]] + [[?{Modifikator|0}]] ]]}}`; That worked fine. Thanks for reading anyways. :-) Cheers!
1631556527
vÍnce
Pro
Sheet Author
Loki said: Ok,.problem solved. Just for the case that someone else has this problem: It's very important that the baseRoll has the right apostrophes. let baseRoll = `&{template:splittermond_test} {{name=${rollName}}} {{charactername=@{character_name}}} {{Probe=[[ [[2d10]] + [[?{Modifikator|0}]] ]]}}`; That worked fine. Thanks for reading anyways. :-) Cheers! JS neophyte here... For clarity, is baseRoll wrapped with backticks because it is a  template literal ?
1631557405
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Yep, that's right Vince.
1631577411
Oosh
Sheet Author
API Scripter
Using a good IDE for your coding will highlight simple syntax errors before they become.... errors. Takes a bit of setting up, but can save you an awful lot of wasted time later: let   baseRoll1  =  "&{template:splittermond_test} {{name=${rollName}}}" ; let   baseRoll2  =  `&{template:splittermond_test} {{name= ${ rollName } }}` ; Also as an aside, you might want to consider a 'default' fallback for your switch block, in case a value that isn't 1, 2 or 3 creeps in to the attribute. You could move the "case 2" part down to the bottom and change it to default and then change the setAttrs to if (+v.dice_mod != 2) - that way your worker will correct any bad value found in dice_mod automatically, and throw out a standard roll. Might be totally unnecessary, or might not work at all if dice_mod can have other values - I'm not familiar with the sheet. But it's always handy to cover potential errors where it doesn't cost you anything :)
1631610393
Loki
Sheet Author
Thanks Oosh, that sounds very useful! :) Cheers!