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

Syntax Error on API command

1566011358

Edited 1566011877
I'm trying out a script which should take in some arguments and produce roll template to chat. The single line I was able to track the problem to is  let args = msg.content.split('!!'); The input message is (first argument is an id of repeating row)  !shoot!!-lmbd2byunlt6xjpod01!!Heavy pistol!!single Every time I tried that I got following error:  SyntaxError: Expected "(", ".", "[", "abs(", "ceil(", "d", "floor(", "round(", "t", "{", [ |\t], [+|\-] or [0-9] but "w" found. undefined I've debugged A LOT and what I came up with has no reasonable explanation from my point of view.  let args = msg.content.split('!!'); log(args[0]); log(args[1]); log(args[2]); log(args[3]); args = args.slice(1, args.length); log(args); let id = args[0]; let weaponName = args[1]; let shotType = args[2]; switch (shotType) { case "single": ... ; break; case "burst": ... ; break; case "auto": ... ; break; } This code, when executed on chat messages that has third argument equals to "single" or "burst" (i.e. !shoot !!id!!name!!single) produces Syntax Error mentioned before. Nothing get's logged after split statement line. When third argument is "auto" everything works without an error. This behaviour is dependant on what are values in first two case clauses of switch statement, because why the hell not.  Can somebody please help me? I'm going crazy over this. 
1566012318
The Aaron
Roll20 Production Team
API Scripter
Can you post the script in its entirety?
So, as usual, just as I posted this I tried something else and it worked for some reason. I'm still interested why it didn't work though. Here's not working version: on("chat:message", function(msg) { if(msg.type == "api" && msg.content.indexOf("!shoot") !== -1) { log(msg.content); let rollTemplate = "&{template:default} "; let args = msg.content.split('!!'); log(args[0]); log(args[1]); log(args[2]); log(args[3]); args = args.slice(1, args.length); log(args); let id = args[0]; let weaponName = args[1]; let shotType = args[2]; log(shotType); switch (shotType) { case "single": rollTemplate = rollTemplate.concat( `{{name=Single shot from ${weaponName}} `, "{{attack=[[1d10 + @{ref_modified} + @{marksmanship} + @{weapon_accuracy}]]}} ", "{{damage=[[@{weapon_damage}]]}} ", "{{location=[[1t[Hit-Location]]]}} " ); break; case "burst": rollTemplate = rollTemplate.concat( `{{name=Burst from ${weaponName}} `, "{{attack=[[1d10 + @{ref_modified} + @{marksmanship} + @{weapon_accuracy}]]}} ", "{{damage=[[@{weapon_damage}]], [[@{weapon_damage}]], [[@{weapon_damage}]]}} ", "{{location=[[3t[Hit-Location]]]}}" ); break; case "auto": let targets = args[3]*1; let range = args[4]; let rof = args[5]*1; let toHitNumber = args[6]*1; let blankSpots = targets - 1; let attackMod = (range === "close" ? +1 : -1) * Math.floor(rof / 10); let bulletsPerTarget = Math.floor(rof / (targets + blankSpots)); rollTemplate = rollTemplate.concat(`{{name=Auto fire from ${weaponName}}} `); for (let i = 1; i <= targets; i++) { rollTemplate = rollTemplate.concat( `{{Target ${i}}} `, `{{Bullets hit=[[(1d10 + @{ref_modified} + @{marksmanship} + @{weapon_accuracy} + ${attackMod}) - ${toHitNumber}]] (${bulletsPerTarget} max}} `, `{{Roll damage and location for each bullet hit}} ` ) } break; default: log("default"); } log(rollTemplate); sendChat(msg.who, rollTemplate); } }); And here's one that works:  on("chat:message", function(msg) { if(msg.type == "api" && msg.content.indexOf("!shoot") !== -1) { log(msg.content); let rollTemplate = "&{template:default} "; let args = msg.content.split('!!'); log(args[0]); log(args[1]); log(args[2]); log(args[3]); args = args.slice(1, args.length); log(args); let id = args[0]; let weaponName = args[1]; let shotType = args[2]; log(shotType); switch (shotType) { case "single": rollTemplate = rollTemplate.concat( `{{name=Single shot from ${weaponName}}} `, `{{attack=[[1d10 + @{${msg.who}|ref_modified} + @{${msg.who}|marksmanship} + @{${msg.who}|repeating_weapons_${id}_weapon_accuracy}]]}} `, `{{damage=[[@{${msg.who}|repeating_weapons_${id}_weapon_damage}]]}} `, "{{location=[[1t[Hit-Location]]]}} " ); break; case "burst": rollTemplate = rollTemplate.concat( `{{name=Burst from ${weaponName}}}`, `{{attack=[[1d10 + @{${msg.who}|ref_modified} + @{${msg.who}|marksmanship} + @{${msg.who}|repeating_weapons_${id}_weapon_accuracy}]]}} `, "{{damage=[[@{weapon_damage}]], [[@{weapon_damage}]], [[@{weapon_damage}]]}} ", "{{location=[[3t[Hit-Location]]]}}" ); break; case "auto": let targets = args[3]*1; let range = args[4]; let rof = args[5]*1; let toHitNumber = args[6]*1; let blankSpots = targets - 1; let attackMod = (range === "close" ? +1 : -1) * Math.floor(rof / 10); let bulletsPerTarget = Math.floor(rof / (targets + blankSpots)); rollTemplate = rollTemplate.concat(`{{name=Auto fire from ${weaponName}}} `); for (let i = 1; i <= targets; i++) { rollTemplate = rollTemplate.concat( `{{Target ${i}}} `, `{{Bullets hit=[[(1d10 + @{${msg.who}|ref_modified} + @{${msg.who}|marksmanship} + @{${msg.who}|repeating_weapons_${id}_weapon_accuracy} + ${attackMod}) - ${toHitNumber}]] (${bulletsPerTarget} max}} `, `{{Roll damage and location for each bullet hit}} ` ) } break; } log(rollTemplate); sendChat(msg.who, rollTemplate); } }); I guess that previous behaviour was somehow caused by missing } on this line `{{name=Single shot from ${weaponName}} `, but how it affected logging and execution flow is beyond me. Perhaps it somehow corrupted output to the console?  
1566015187
The Aaron
Roll20 Production Team
API Scripter
Yeah, that is strange.  I wouldn't expect it to have done that.  The error you got is from the Dice Engine: SyntaxError: Expected "(", ".", "[", "abs(", "ceil(", "d", "floor(", "round(", "t", "{", [ |\t], [+|\-] or [0-9] but "w" found. happens when you have something like: [[w]] or [[ whoops 1d6 ]] Something in the substitutions you're sending to chat might have been in the wrong place.  Hard to say.