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 .
×

[Help] sendChat giving errors with inline rolls

I'm trying to write a script that will read spell information from my custom SR2 character sheet and spit out all the relevant rolls into a default (for now) powercard. so the roll button sends this: !cast|@{character_name}|@{character_id}|@{spellname}|@{castforce}|@{will_aug}|@{drain}|?{How many dice are you taking for casting?|0}|?{How many dice are you taking to resist the drain?|0}|[[@{castTN}+2*(@{spellstack}+@{spellsus})+@{spellmisc}+@{stun_pen}+@{wound_pen}]] and all of the information is received properly based on my previous debug logging. The script then does the math to figure out what the target number should be and, in thoery, sends the rolls back to chat. cast: function(msg) { if (!msg.inlinerolls) return; var input = msg.content.split('|'); var charName = input[1]; var charID = input[2]; var spellname = input[3]; var force = input[4]; var will = input[5] var drainMod = input[6]; if (drainMod == '') drainMod = 0; var drainTN = Math.floor(force / 2) + drainMod; if (drainTN < 2) drainTN = 2; var castpool = input[7]; var drainpool = input[8]; var TN = msg.inlinerolls[0].results.total; if (TN < 2) TN = 2; var message = "&{template:default} {{name=" + spellname + "}} {{ Casting Test = [[ [" + force + "d6>" + TN + "!!] ]] }} {{ Pool Dice (Casting) = [[ [" + castpool + "d6>" + TN + "!!] ]] }} {{ Drain Test = [[ [" + will + "d6>" + drainTN + "!!] ]] }} {{ Pool Dice (Drain) = [[ [" + drainpool + "d6>" + drainTN + "!!] ]] }}"; log(message); sendChat("character|" + charID, message); } But as soon as I include the sendChat line, and click the button I get this error: ^SyntaxError: Expected "(", ".", "[", "abs(", "ceil(", "d", "floor(", "round(", "t", "{", [ |\t], [+|\-] or [0-9] but end of input found. I know that my problem isn't with formatting it into the card, because when I use the same message but with just text rather than the rolls it works fine, so it has to be the inline rolling. I've seen other scripts and threads here that use inline rolls in their output without error. Does anyone know how I can fix this without completely rewriting the output format? Cheers, Crazion
1452487466

Edited 1452487479
Lithl
Pro
Sheet Author
API Scripter
You've got one too many pairs of square brackets in your inline rolls. Your roll is essentially coming out as "[[ [5d6>10!!] ]]". The double brackets on the outside make it an inline roll, but the single brackets on the inside make what you're trying  to roll into a comment, that's meant to be ignored by the dice engine. However, the lexer for the dice engine doesn't like comments in an inline roll unless at least some dice expression (even if it's 0d0) is included, which is where the error is coming from.
Thanks Brian, I added those in as a guess at fixing the error I was receiving before. So now I am back to having a roll that looks like this: &{template:default} {{name=Manaball}} {{ Casting Test = [[ 4d6>6!! ]] }} {{ Pool Dice (Casting) = [[ 4d6>6!! ]] }} {{ Drain Test = [[ 6d6>2!! ]] }} {{ Pool Dice (Drain) = [[ 4d6>2!! ]] }} give me  this error: SyntaxError: Expected "[" or [ |\t] but "4" found. which I know is refering to the Casting Test, because if I change that number around the error follows it. Now, another way to fix this would be if anyone knows a way to do the math for the TN without the API. Every time I've tried this before, depending on where I put brackets, I just get the number of dice being rolled or the sum of the dice being rolled, when I want the number of successes. Any thoughts?
Just fyi... that's a roll template. Not a powercard. :D
I was actually just learning that before checking for more responses. I can't get custom templates to work either. I don't know what's wrong with me, but my scripts never seem to work like they should even with other people looking them over. (In other languages too)
1452518997
Lithl
Pro
Sheet Author
API Scripter
Crazion D. said: Thanks Brian, I added those in as a guess at fixing the error I was receiving before. So now I am back to having a roll that looks like this: &{template:default} {{name=Manaball}} {{ Casting Test = [[ 4d6>6!! ]] }} {{ Pool Dice (Casting) = [[ 4d6>6!! ]] }} {{ Drain Test = [[ 6d6>2!! ]] }} {{ Pool Dice (Drain) = [[ 4d6>2!! ]] }} give me  this error: SyntaxError: Expected "[" or [ |\t] but "4" found. which I know is refering to the Casting Test, because if I change that number around the error follows it. Remove the leading space on the inline rolls, at least: on('chat:message', function(msg) {     if (msg.content === '!test') {         sendChat('System', '&{template:default} {{name=Manaball}} {{ Casting Test = [[4d6>6!! ]] }} {{ Pool Dice (Casting) = [[4d6>6!! ]] }} {{ Drain Test = [[6d6>2!! ]] }} {{ Pool Dice (Drain) = [[4d6>2!! ]] }}');     } }); There's a lot of other spaces you don't need in there, but the leading space is the source of the error. This is only a problem with parsing the message from the API, as the macro you posted works fine if done straight from the chat. Crazion D. said: Now, another way to fix this would be if anyone knows a way to do the math for the TN without the API. Every time I've tried this before, depending on where I put brackets, I just get the number of dice being rolled or the sum of the dice being rolled, when I want the number of successes. Any thoughts? Sure. Basically, while the right side of an inequality (> or <) has to be a number instead of a calculation, you can nest inline rolls inside each other: Casting Test: [[@{castforce}d6>[[{@{castTN}+2*(@{spellstack}+@{spellsus})+@{spellmisc}+@{stun_pen}+@{wound_pen}, 2}kh1]]!!]] Pool Dice (Casting): [[?{Dice for casting|0}d6>[[{@{castTN}+2*(@{spellstack}+@{spellsus})+@{spellmisc}+@{stun_pen}+@{wound_pen}, 2}kh1]]!!]] Drain Test: [[@{will_aug}d6>[[{floor(@{castforce} / 2) + @{drain}, 2}kh1]]!!]] Pool Dice (Drain): [[?{Dice to resist drain?|0}d6>[[{floor(@{castforce} / 2) + @{drain}, 2}kh1]]!!]] By wrapping the target number in another set of square brackets for a nested inline roll, it gets processed into a single number, which can be used as an actual target number. The {X, Y}kh1  syntax is keep the higher value between two numbers, equivalent to the "if (drainTN < 2) drainTN = 2;" and "if (TN < 2) TN = 2;" lines from your script.
Brian, I both love and hate you right now. I mean it's my fault for not looking more deeply into things, and you couldn't have answered this question before I asked it, but this knowledge could have saved me probably 10 hours of coding. But at the same time you have just saved me hours and hours more time trying to fix it. Side note: I figured out why my custom roll templates were not working: once again extra spaces put into the macro for readability were causing it to not match properties to the correct inputs.