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

Custom roll parsing passing non roll not being read properly

1639653202

Edited 1639656753
Matthew C
Pro
Sheet Author
Hey, before I start I just want you to know that I am not using the non roll in the sheetworker script, it is just being passed through Now, I have a field that is filled in through a sheetworker, using the side bar in chrome I can check the coding and the variable is showing the changed value But when I actually use the value in the roll template it shows as empty     on("change:repeating_war:activeN", function(eventInfo) {         if (eventInfo.sourceType === 'sheetworker') return;         const output = {};         getAttrs(['repeating_war_activeN', 'repeating_war_activeSlot', 'repeating_war_activeName'], function(values) {             output["repeating_war_activeSlot"] = eventInfo.newValue ? eventInfo.newValue : "Active WAR";             output["repeating_war_activeName"] = eventInfo.newValue ? eventInfo.newValue : "Active WAR";             setAttrs(output);         });     }); on('clicked:repeating_war:damage', (info) => {         startRoll("&{template:active} {{type=[[@{repeating_war_activeType}]]}} {{name=@{repeating_war_activeName}}} {{typeName=@{repeating_war_activeTypeName}}} {{prefix=0}} {{suffix=0}} {{opposing=[[0]]}} {{baseRoll=[[0]]}} {{underwhelming=[[0]]}} {{overwhelming=[[0]]}} {{rollResult=[[0]]}} {{critical=[[0]]}} {{mitigation=[[0]]}} {{roll=[[1d10]]}} {{result=[[0]]}} {{whelming=[[1d10]]}} {{bonus=(?{Bonus Modifier|0})}} {{target=[[?{Opposing Statistic|0}]]}} {{defence=[[0]]}} {{resistance=[[0]]}}", (results) => {             const roll = results.results.roll.result;             console.log(results);             const overwhelming = roll + results.results.whelming.result;             const underwhelming = roll - results.results.whelming.result;             const critical = results.results.whelming.result;             const defence = results.results.defence.result;             const mitigation = results.results.mitigation.result;             const resistance = results.results.resistance.result;             //const type = results.results.type.result;             const opposing = results.results.target.result;             const opposingDefence = defence > opposing ? 1 : 0;             const opposingResistance = resistance > opposing ? 1 : 0 ;             finishRoll(                 results.rollId,                 {                     //rollResult: type === 1 ? roll + mitigation : roll + resistance,                     roll: roll === 10 ? overwhelming : roll === 1 ? underwhelming : roll,                     baseRoll: roll === 10 ? critical : roll === 1 ? critical : roll,                     //opposing: type === 1 ? opposingDefence : opposingResistance,                     //overwhelming: type === 1 ? overwhelming + mitigation : overwhelming + resistance,                     //underwhelming: type === 1 ? underwhelming + mitigation : underwhelming + resistance,                     result: roll === 10 ? 1 : roll === 1 ? -1 : 0,                     critical: critical === 10 ? 1 : 0                 }             );         });     }); < rolltemplate class = "sheet-rolltemplate-active" >     < div class = "sheet-template-container" >         < div class = "sheet-template-header" > Active WAR: {{name}} </ div >         < div class = "sheet-template-subheader" > {{typeName}} </ div >         < div class = "sheet-template-row-outcome" > {{outcome}} </ div >     </ div > </ rolltemplate > It is a very simple rolltemplate, but the {{name}} is showing as blank
1639675261

Edited 1639675471
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Welcome to sheet coding! There are a few issues at play here. Sheet listeners must be all lowercase even if the actual attribute name has uppercase letters, so your first listener probably is never firing on a change to activen. This is one of several reasons why the recommended naming schema is to use snake_case instead of camelCase for attribute names. When you send a reference to a repeating attribute in start roll, you have to specify the rowid of the attribute you are looking for. Start roll doesn't get that for you. You can parse the rowid out of info.triggerName like so: const parseClickTrigger = function(string){ let match = string.match(/clicked:(?:(repeating_[^_]+)_([^_]+)_)?(.+)/); match.shift(); return match; }; let [section,rowID,button] = parseClickTrigger(info.triggerName);
1639720755

Edited 1639722479
Matthew C
Pro
Sheet Author
ah perfect very nice, will try this and let you know :D Thanks a bunch The weird thing is, the first one that shouldn't be firing is actually firing, since the sheet itself is updating normally :p but I will look into changing to snake case to prevent any issues down the road Update, took some digging around, but got it to work, couldn't figure out how to get the variable into the roll, but some quick searches sorted me out, so now this is working 100% thanks a million
1639733929
GiGs
Pro
Sheet Author
API Scripter
Matthew C said: The weird thing is, the first one that shouldn't be firing is actually firing, since the sheet itself is updating normally :p but I will look into changing to snake case to prevent any issues down the road The "capitals on that first line" is erratic - sometimes it works. But you should always use lower case letters there as Scott suggests, because it sometimes won't work and you won't know why (in my experience, the only time you can guarantee it working is when someone is pointing out that it shouldn't work..), and because the offical documentation tells you to only use lower case letters there. So, if it sometimes works, that doesn't change the advice: always use lower case letters on that line. When it causes your worker to fail, you'll spend a long time trying to figure out why its not working, and then notice the sneaky capital letter there.
1639736360
Andreas J.
Forum Champion
Sheet Author
Translator
GiGs said: So, if it sometimes works, that doesn't change the advice: always use lower case letters on that line. When it causes your worker to fail, you'll spend a long time trying to figure out why its not working, and then notice the sneaky capital letter there. And to generalize, using all lowercase for attribute names in both the HTML and in sheetworkers is the smart choice, keeping things consistent, along with avoiding any issues as mentioned here.
1639740357
Matthew C
Pro
Sheet Author
Yeah I can completely agree with that and I do know what you mean that things not supposed to work do to prove a point and then stop once you release (could also be the custom sandbox where it works, but normal games wont XD)