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

Can't pinpoint syntax error in custom roll parsing

1704763658

Edited 1704763720
I should start by saying that I'm still very much a novice when it comes to all of this, and thank you once again to all of the experts here. I genuinely don't know what I would do with out you. That aside, I'm attempting to use custom roll parsing for a roll within the modified Fallout VnD PnP sheet I'm working on, specifically to handle queries pertaining to whether an attack is Targeted or Not Targeted, and providing relevant values depending on the selection, as this was a lot for a standard macro to handle, at least as far as I could tell. The "Non Targeted" works without issue.  However, when selecting "Yes" for the targeted, and selecting the targeted area, as in "head," I'm left with a syntax error in the console that I can't quite figure out.  The Sheet Worker and an image of the syntax error are below. <script type="text/worker"> const targetAreaData = { head: { penalty: "60", effect: "LR -3; 15 True; Dazed for one turn" }, torso: { penalty: "20", effect: "LR -2; 5 True; Knocked Down" }, arm: { penalty: "40", effect: "LR -1; 10 True" }, leg: { penalty: "40", effect: "LR -1; 10 True" }, groin: { penalty: "60", effect: "LR -4; 20 True; 10 Bleed" } }; on('clicked:roll', () => { startRoll("!{{template:default}}{{targeted=![[?{Is the attack targeted?|No,0|Yes,1}]]}}", question => { console.log("Targeted query response:", question); const isTargeted = question.results.targeted.result; if (isTargeted) { startRoll(`!{{template:default}}{{targetArea=![[?{Attack Type|head|torso|arm|leg|groin}]]}}`, targetAreaResponse => { console.log("Target area response:", targetAreaResponse); const targetArea = targetAreaResponse.results.targetArea.result; const { penalty, effect } = targetAreaData[targetArea]; const rollStringTargeted = `&{template:weapon} {{char-name=@{character_name}}} {{name=@{weapon_name-1}}} {{selected-skill=@{selected_skill_name}}} {{wpn-skill=[[@{weapon_select-1}]]}} {{roll=[[${penalty}]] [Trgt Penalty] + [[?{Trgt Mod|0}]][Trgt Mod]) - ([[?{Hit Chance|0}]][Hit Chance]) + ([[?{Armor Class|0}]][AC] + [[@{ac_reduction-1}]][AC Reduc.]) + 1d100cs<[[{[[@{critical_chance} + (?{Crit Bonus|0})]],50}kl1]]cf>[[{[[90+@{luck_base}]],100}kl1]]}} {{Dmg=[[@{weapon_damage-1}cs0cf0]]}} {{DT=@{dt_reduction-1}}} {{Dmg Type=@{weapon_damage_type-1}}} {{notes=@{weapon_notes-1}}} {{Location Effect=${effect}}}`; console.log("Roll string targeted:", rollStringTargeted); startRoll(rollStringTargeted, roll => { finishRoll(roll.rollId); }); }); } else { const rollStringNonTargeted = `&{template:weapon} {{char-name=@{character_name}}} {{name=@{weapon_name-1}}} {{selected-skill=@{selected_skill_name}}} {{wpn-skill=[[@{weapon_select-1}]]}} {{roll=[[0 - ([[?{Hit Chance|0}]][Hit Chance]) + ([[?{Armor Class|0}]][AC] + [[@{ac_reduction-1}]][AC Reduc.]) + 1d100cs<[[{[[@{critical_chance} + (?{Crit Bonus|0})]],50}kl1]]cf>[[{[[90+@{luck_base}]],100}kl1]]]]}} {{Dmg=[[@{weapon_damage-1}cs0cf0]]}} {{DT=@{dt_reduction-1}}} {{Dmg Type=@{weapon_damage_type-1}}} {{notes=@{weapon_notes-1}}}`; console.log("Roll string non-targeted:", rollStringNonTargeted); startRoll(rollStringNonTargeted, roll => { finishRoll(roll.rollId); }); } }); }); </script> I've tried using console logs for debugging, as you can see, but everything cuts off as soon as I've selected a targeted area and continued.   In this particular test I selected "groin," which is presumably the syntax error 'g' mentioned. Again, I'm completely at a loss for where it's falling short, but I figured more experience eyes might be able to tell where I messed up. Thank you once again for any help provided!
1704765022
GiGs
Pro
Sheet Author
API Scripter
When you get a roll syntax error, that indicates there's (probably) a problem with the roll, not the sheet worker. Continue working on it as a sheet worker creates an extra layer that makes it hard to figure out what's going on. Copy just that roll into an ability on the character sheet, fill in anything you need (like penalty and effect), and experiment with it till you get it working. Then put it back into the sheet worker.
1704765122

Edited 1704765164
GiGs
Pro
Sheet Author
API Scripter
I see a problem immediately in the roll: {{wpn-skill=[[@{weapon_select-1}]]}} This should probably be {{wpn-skill=[[@{weapon_select}-1]]}} I havent looked at the rest of the roll, so it might not be the only issue, but that is definitely a problem.
Thank you for responding GiGs! Regarding the @{weapon_select-1} attribute, that was how it was already named when I took on the sheet.  It worked fine even within that context. I did as you recommended, testing the roll by itself.  When I input numeric values into penalty, it worked just fine.  What this is telling me is that in this part of the roll {{roll=[[${penalty}]] [Trgt Penalty] ${penalty} is being replaced by "head" rather than its assigned numeric value in the const const targetAreaData = { head: { penalty: "60", effect: "LR -3; 15 True; Dazed for one turn" } is it that I've set this section up improperly perhaps?
1704778762

Edited 1704779583
GiGs
Pro
Sheet Author
API Scripter
I just assumed that was an attribute where 1 was subtracted from it, rather than the -1 being part of the attribute name. I'd check that each attribite name is correct and exists with a value on the sheet. Regarding your specific question, it sounds like this part is causing the error: const { penalty, effect } = targetAreaData[targetArea]; I'm too sleepy to examine it properly now, but I'd recommend changing this temporarily to const penalty = +targetAreaData[targetArea].penalty || 0; const effect = targetAreaData[targetArea].effect; console.log({targetAreaData, targetArea, penalty, effect}); The first  two lines to simplify the data collection and see if the correct values are being assigned, and the console line to see each variable has the value it is supposed to have. Also, test your roll with the penalty part removed, and see if it now works. If so, you know the error is there.
1704779078
GiGs
Pro
Sheet Author
API Scripter
I do see another problem. {{roll=[[${penalty}]] [Trgt Penalty] + //the rest // For the rollTemplate output you might need to wrap the entire roll= part in another set of inline roll brackets, so that the whole roll is a single numeric value, like {{roll=[[ [[${penalty}]] [Trgt Penalty] + //the rest // ]]
1704779452

Edited 1704779470
GiGs
Pro
Sheet Author
API Scripter
That does look like a very complex roll, so I'd test each part of it outside the sheet worker. You can change its structure a bit too. This {roll=[[${penalty}]] [Trgt Penalty] + [[?{Trgt Mod|0}]][Trgt Mod]) - ([[?{Hit Chance|0}]][Hit Chance]) + ([[?{Armor Class|0}]][AC] + [[@{ac_reduction-1}]][AC Reduc.]) + 1d100cs<[[{[[@{critical_chance} + (?{Crit Bonus|0})]],50}kl1]]cf>[[{[[90+@{luck_base}]],100}kl1]] can be written as something like (getting rid of unneeded [[ ]] brackets, and breaking out the full penalty declaration) {roll=[[ ${+targetAreaData[targetArea].penalty || 0} [Trgt Penalty] + ?{Trgt Mod|0}[Trgt Mod]) - (?{Hit Chance|0}[Hit Chance]) + (?{Armor Class|0}[AC] + @{ac_reduction-1}[AC Reduc.]) + 1d100cs<[[{@{critical_chance} + (?{Crit Bonus|0}),50}kl1]]cf>[[{90+@{luck_base},100}kl1]] ]]
1704785858
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Your syntax error is because you are getting a string back as your location. that doesn't work in a roll. You can extract it by putting it in roll tags though.
1704821086

Edited 1704821180
GiGs
Pro
Sheet Author
API Scripter
I didn't see it at first, but Scott is referring to this line: startRoll(`!{{template:default}}{{targetArea=![[?{Attack Type|head|torso|arm|leg|groin}]]}}`, targetAreaResponse => { see that targetArea? It has to be a number if you have [[ ]] brackets around it, and if it's not a number, you can't use it as a result of a query. I got it it to work with the following changes: const targetAreaData = {         1 : { penalty: "60" , effect: "LR -3; 15 True; Dazed for one turn" },         2 : { penalty: "20" , effect: "LR -2; 5 True; Knocked Down" },         3 : { penalty: "40" , effect: "LR -1; 10 True" },         4 : { penalty: "40" , effect: "LR -1; 10 True" },         5 : { penalty: "60" , effect: "LR -4; 20 True; 10 Bleed" }     };     on ( 'clicked:roll' , () => {         {{{{ noop }}}}         startRoll ( "!{{template:default}}{{targeted=![[?{Is the attack targeted?|No,0|Yes,1}]]}}" , question => {             console . log ( "Targeted query response:" , question );             const isTargeted = question . results . targeted . result ;             console . info ({ isTargeted });             if ( isTargeted ) {                 startRoll ( `!{{template:default}}{{targetArea=[[?{Attack Type|head,1|torso,2|arm,3|leg,4|groin,5}]] }}` , targetAreaResponse => {                     console . log ( "Target area response:" , targetAreaResponse );                     const targetArea = targetAreaResponse . results . targetArea . result ;                     const { penalty , effect } = targetAreaData [ targetArea ];                     console . info ({ targetArea , penalty , effect }); Notice that problematic line now gives a number output and the earlier targetAreaData object needed revising.