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

Some in-line roll not evaluated in a roll template generated from an API script

1543656354
StéphaneD
Pro
Sheet Author
API Scripter
Hi all I am writing an API script that builds a command message issued to the chat via sendChat(). At runtime, all in-line rolls in the template are evaluated excepted one when running via the script, and no 3D dice are displayed. If I copy the chunk not evaluated (in the {{degats= }} tag below) and paste it to the chat, it evaluates as expected. If I copy the whole generated message and paste it to the chat, it all works as expected, performing the 3D rolls The chat command that my script builds and sends to the chat is the following : &{template:co1} {{perso=Looping}} {{subtags=Attaque}} {{name=@{Looping|repeating_armes_$0_armenom}}} {{desc=@{Looping|repeating_armes_$0_armejetn}}} {{attaque=[[1d20cs>20cf<2[Dé] + ([[@{Looping|repeating_armes_$0_armeatk}]])[Attaque] + ([[@{Looping|visee_att}]])[Tir visé] - ([[@{Looping|arc_feu}*3]])[Arc de feu] + ([[@{Looping|distance}]])[Portée] ]]}} {{degats=[[ 2d6![DM] + [[@{Looping|repeating_armes_$0_armedmcar}]][Mod.DM] + [[@{Looping|visee_dm}]][Tir] - [[@{Looping|arc_feu}*3]][Arc de feu] + [[@{Looping|repeating_armes_$0_armedmdiv}]][Bonus DM] ]]}} {{special=@{Looping|repeating_armes_$0_armespec}}} Any idea ? TIA
1543751275

Edited 1543778492
StéphaneD
Pro
Sheet Author
API Scripter
More on this one : selecting different options on the character sheet, the same generated command as above is issued with different attributes values and ends up with the following error in the API sandbox : SyntaxError: Expected "[" or [ |\t] but "2" found. undefined Which is unfortunately not very helpful As far as I can see, the only attribute that would evaluate to 2 is the @{Looping|visee_att}, where 'visee_att' is set to a value of '@{PER}' which itself is an autocalc field set to a value of 'floor((@{PERCEPTION}-10)/2)' and the PERCEPTION attribute value on the character sheet is 14 Anyone ? TIA
1544351637
StéphaneD
Pro
Sheet Author
API Scripter
Hello there Tried to go a different route with my script by making sure an attribute is created for the repeating section roll button field on the character sheet (was not the case prior to that). Then changed my script to sendChat() a command similar to %{character|repeating_section_$n_rollname} -- which works when issued directly in the chat window. This time the API console is showing this error message : ReferenceError: chracter is not defined at eval (eval at <anonymous> (/home/node/d20-api-server/api.js:155:1), <anonymous>:468:61) at RegExp.[Symbol.replace] (native) at String.replace (native) at eval (eval at <anonymous> (/home/node/d20-api-server/api.js:155:1), <anonymous>:452:21) at RegExp.[Symbol.replace] (native) at String.replace (native) at Object.d20.textchat.doChatInput (eval at <anonymous> (/home/node/d20-api-server/api.js:155:1), <anonymous>:368:29) at sendChat (/home/node/d20-api-server/api.js:1788:16) at displayActions (apiscript.js:187:7) at Object.apiCommand (apiscript.js:234:10) Sounds like a typo in some Roll20-owned .js script ? TIA
1544352289
Ziechael
Forum Champion
Sheet Author
API Scripter
Hi Stéphane, first off, apologies that this seems to have flown under the radar for the past week! I'm going to move your post over to the API forum initially since it is likely an issue with the script you are writing, I know 3D dice don't play nice with the API but am far from an expert! It could be worth linking to, or posting, your scripts code thus far so that the true experts can lend assistance. If it transpires that this is a bug with the VTT itself I'll gladly move this back to the bug forum and we can pursue more traditional methods. Best of luck!
1544364546

Edited 1544364654
Ammo
Pro
I believe the anonymous JavaScript that is being evaluated with lines numbered 468 and 452 is the generated character sheet script ( ChroniquesOubliees?).  But there isn't any code that matches this error in the current version of that sheet on github, so maybe not? I find it doubtful that the problem is in there anyway, if I understood your post above correctly.  You said you can run the entire template invocation by pasting to chat and it works, but if you run the same template through sendChat, it breaks? That suggests to me the different errors you are getting from different cases is because the parser has already derailed by the time it detects this error, so you are looking at nonsense error messages. If that is the case,  I only have one random theory. Is there maybe a chance one of your international characters is being decoded/encoded incorrectly when passed through the API?   I am grasping at straws, I know.   But it might be good to rule this out.  When you copy and paste your text to the chat, your stuff goes through content encoding via the client side and maybe that "cleans" something in there?   I am suggesting some character in your query is being incorrectly encoded/decoded and you end up with junk in the query, throwing the parser off. To rule this out, just recreate the sendChat contents without any international characters and without copying and pasting the text you already have. Since you are pulling some of the content from the character attributes, you may add some code to strip any non-ASCII characters.  You could for example have something that looks like 'a' but is really some crazy UTF-8 sequence that just happens to look like 'a' but breaks the parser.   Ok, enough wild-ass theory.  I have no evidence that this is correct, so please don't waste your time chasing it.  I was intrigued by your weird error messages, and this is my initial 'feeling' of what it might be. Bon courage, Ammo PS: Maybe ask the authors of your character sheet what they think this is? Stéphane D said: Hello there Tried to go a different route with my script by making sure an attribute is created for the repeating section roll button field on the character sheet (was not the case prior to that). Then changed my script to sendChat() a command similar to %{character|repeating_section_$n_rollname} -- which works when issued directly in the chat window. This time the API console is showing this error message : ReferenceError: chracter is not defined at eval (eval at <anonymous> (/home/node/d20-api-server/api.js:155:1), <anonymous>:468:61) at RegExp.[Symbol.replace] (native) at String.replace (native) at eval (eval at <anonymous> (/home/node/d20-api-server/api.js:155:1), <anonymous>:452:21) at RegExp.[Symbol.replace] (native) at String.replace (native) at Object.d20.textchat.doChatInput (eval at <anonymous> (/home/node/d20-api-server/api.js:155:1), <anonymous>:368:29) at sendChat (/home/node/d20-api-server/api.js:1788:16) at displayActions (apiscript.js:187:7) at Object.apiCommand (apiscript.js:234:10) Sounds like a typo in some Roll20-owned .js script ? TIA
1544369988
StéphaneD
Pro
Sheet Author
API Scripter
Hey Ammo, Thanks for your insight and theory -- I have been struggling with this for over a week, with not much feedback from anyone on the original forum where I apparently erroneously posted it, so some interest from someone is most welcome ! ;) As for your theory, I tried to do as you suggested. The only french accented character I could see was in the {{subtag}} key in the macro command associated with the roll button so I changed the HTML to Capacit&amp;eacute;&nbsp; I have added some logging to the script. Here is what it outputs in the console before breaking at the weird parsing error : "COLib | @{togm}&amp;{template:co1} {{perso=@{character_name}}} {{name=@{jetcapanom}}} {{subtags=Capacit&amp;eacute;}} {{carac=[[ @{jetcapanbde}d@{jetcapade}@{jetcapatypjet} + [[@{jetcapacarac}]][Bonus] + @{jetcapadiv}[Divers] ]]}} {{desc=@{jetcapadesc}}}" "COLib | %{Looping|repeating_jetcapas_$0_jet}" The first line is the value of the button roll stored in the 'repeating_jetcapas_$0_jet' attribute The second line is what is passed as the second parameter to sendChat() The values of the other attributes on the command are : - character_name = 'Looping' (no funky french accent) - jetcapanom = 'Pilotage' (no funky french accent) - jetcapanbde is '2' - jetcapade is @{ETATDE} which evaluates to '20' - jetcapatypjet is 'kh1' - jetcapacarac is @{DEX} which evaluates to a DEX modifier of '3' - jetcapadiv is '1' - jetcapadesc is empty So I'm only trying to roll 2d20, add 3 and 1 to the best of the two, and display it in the default roll template for the 'ChroniquesOubliéesContemporain' charsheet. You're right saying that if I take the command passed to sendChat() and paste it directly in the chat window, it works as expected (ie typing&nbsp; %{Looping|repeating_jetcapas_$0_jet} and pressing enter) I have an ability shown as a token action which says '!co-actions --competences' This one goes and spins through the 'jetcapas' repeating section, creating an API command button for each entry that says '!co-actions --competence n' (where 0 &lt; n &lt; nth-repeating-row -1) The command that breaks the parser is '!co-actions --competence 0' which does the sendChat with the value shown above -- which does not have any funky accent / UTF8 issue as far as I can tell Finally, I am also the sheet author -- which I have borrowed from Natha's work on Chroniques Oubliées Fantasy, and reworked to support the specific rules in the contemporary flavour of the Chroniques Oubliées french RPG. Here is a link to a Gist with my script :&nbsp; <a href="https://gist.github.com/stephaned68/cc33eca01024d2ffbf58cf4fe00cd455" rel="nofollow">https://gist.github.com/stephaned68/cc33eca01024d2ffbf58cf4fe00cd455</a>
1544370269
The Aaron
Pro
API Scripter
Just to add to the discussion, there is a difference between the parser used by the API sendChat() function and the chat box. Here’s a bug report I made about it:&nbsp; <a href="https://app.roll20.net/forum/post/2217884/api-regressions-for-inline-dice-expression-in-the-sendchat-api-function" rel="nofollow">https://app.roll20.net/forum/post/2217884/api-regressions-for-inline-dice-expression-in-the-sendchat-api-function</a> The error you posted about “Expected ...” is probably related to it. If you put a space in after the [[ for the attribute returning 2, it will probably work for that case. Or possibly take a space out, I can’t quite remember. If you look at RecursiveTable, there’s a sendChat wrapper that attempts to fix the error cases.&nbsp;
The Aaron said: Just to add to the discussion, there is a difference between the parser used by the API sendChat() function and the chat box. Here’s a bug report I made about it:&nbsp; <a href="https://app.roll20.net/forum/post/2217884/api-regressions-for-inline-dice-expression-in-the-sendchat-api-function" rel="nofollow">https://app.roll20.net/forum/post/2217884/api-regressions-for-inline-dice-expression-in-the-sendchat-api-function</a> The error you posted about “Expected ...” is probably related to it. If you put a space in after the [[ for the attribute returning 2, it will probably work for that case. Or possibly take a space out, I can’t quite remember. If you look at RecursiveTable, there’s a sendChat wrapper that attempts to fix the error cases.&nbsp; All the thumbs up!
1544375956
StéphaneD
Pro
Sheet Author
API Scripter
Hi Aaron Thanks for your input. That was the problem. I removed the extra space between [[ and the number of dice in the roll button value, and I can now issue the command via sendChat() without the weird parsing error in the API console. I already knew you were the champion of Roll20´s API and this confirms it. Thanks a ton dude ;)&nbsp; Now if some Roll20 developer could take a look at this other strange message I got with an undefined chracter variable in their code, and a huge call stack of various js scripts, maybe they can find an explanation for the whole problem. Or at least correct what appears to be a typo... Thanks again !