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

What is API error "ERROR: Unable to find character target in chat command." ?

1508897193
Chris D.
Pro
Sheet Author
API Scripter
Compendium Curator
The API console is logging a lot of errors when certain things happen.  For example whenever I do one command the API console gets anywhere from 15 to 18 of these messages. ERROR: Unable to find character target in chat command.  My API script is not logging this, so  I assume the system is. What does it mean and what precisely causes to to log a bunch of these? Thanks. 
1508898260
The Aaron
Pro
API Scripter
Do you have a simple reproduction script?  I’ve not seen this error before?
1508898828
The Aaron
Pro
API Scripter
What scripts do you have installed?  If you disable any of them, does it go away?
1508909343
Jakob
Sheet Author
API Scripter
This should stem from you using e.g @{Tim|strength} in an API-sent chat message when there's no character named Tim.
1508927086
The Aaron
Pro
API Scripter
Oh!  Actually, I bet it’s a @{target|...} reference. 
1508934521
Jakob
Sheet Author
API Scripter
The Aaron said: Oh!  Actually, I bet it’s a @{target|...} reference.  D'oh, yes!
1508936012
The Aaron
Pro
API Scripter
We should chip in and buy the API a few " characters, would make the error message easier to decipher: ERROR: Unable to find character "target" in chat command. 
1508969677

Edited 1508969711
Chris D.
Pro
Sheet Author
API Scripter
Compendium Curator
Thanks! I bet it is exactly that it should be  ERROR: Unable to find character "target" in chat command. The many, many error messages sometimes appear in the chat log when the API sends the very long string below that produces this. How many targets? 1 2 3 4 5 6 7 8 9 10 The long string that produces this is.  "&{template:default} {{name=How many targets? [1](!edParse~ TargetTypeÒ PD~ TokenListÒ -KjPVHb87Nl0KPEwaI0S~ TargetSetÒ @{target|First Target|token_id}~ ActionÒ TÒ 2Ò 0)[2](!edParse~ TargetTypeÒ PD~ TokenListÒ -KjPVHb87Nl0KPEwaI0S~ TargetSetÒ @{target|First Target|token_id}Ò @{target|Second Target|token_id}~ ActionÒ TÒ 2Ò 0)[3](!edParse~ TargetTypeÒ PD~ TokenListÒ -KjPVHb87Nl0KPEwaI0S~ TargetSetÒ @{target|First Target|token_id}Ò @{target|Second Target|token_id}Ò @{target|Third Target|token_id}~ ActionÒ TÒ 2Ò 0)[4](!edParse~ TargetTypeÒ PD~ TokenListÒ -KjPVHb87Nl0KPEwaI0S~ TargetSetÒ @{target|First Target|token_id}Ò @{target|Second Target|token_id}Ò @{target|Third Target|token_id}Ò @{target|Forth Target|token_id}~ ActionÒ TÒ 2Ò 0)[5](!edParse~ TargetTypeÒ PD~ TokenListÒ -KjPVHb87Nl0KPEwaI0S~ TargetSetÒ @{target|First Target|token_id}Ò @{target|Second Target|token_id}Ò @{target|Third Target|token_id}Ò @{target|Forth Target|token_id}Ò @{target|Fifth Target|token_id}~ ActionÒ TÒ 2Ò 0)[6](!edParse~ TargetTypeÒ PD~ TokenListÒ -KjPVHb87Nl0KPEwaI0S~ TargetSetÒ @{target|First Target|token_id}Ò @{target|Second Target|token_id}Ò @{target|Third Target|token_id}Ò @{target|Forth Target|token_id}Ò @{target|Fifth Target|token_id}Ò @{target|Sixth Target|token_id}~ ActionÒ TÒ 2Ò 0)[7](!edParse~ TargetTypeÒ PD~ TokenListÒ -KjPVHb87Nl0KPEwaI0S~ TargetSetÒ @{target|First Target|token_id}Ò @{target|Second Target|token_id}Ò @{target|Third Target|token_id}Ò @{target|Forth Target|token_id}Ò @{target|Fifth Target|token_id}Ò @{target|Sixth Target|token_id}Ò @{target|Seventh Target|token_id}~ ActionÒ TÒ 2Ò 0)[8](!edParse~ TargetTypeÒ PD~ TokenListÒ -KjPVHb87Nl0KPEwaI0S~ TargetSetÒ @{target|First Target|token_id}Ò @{target|Second Target|token_id}Ò @{target|Third Target|token_id}Ò @{target|Forth Target|token_id}Ò @{target|Fifth Target|token_id}Ò @{target|Sixth Target|token_id}Ò @{target|Seventh Target|token_id}Ò @{target|Eighth Target|token_id}~ ActionÒ TÒ 2Ò 0)[9](!edParse~ TargetTypeÒ PD~ TokenListÒ -KjPVHb87Nl0KPEwaI0S~ TargetSetÒ @{target|First Target|token_id}Ò @{target|Second Target|token_id}Ò @{target|Third Target|token_id}Ò @{target|Forth Target|token_id}Ò @{target|Fifth Target|token_id}Ò @{target|Sixth Target|token_id}Ò @{target|Seventh Target|token_id}Ò @{target|Eighth Target|token_id}Ò @{target|Ninth Target|token_id}~ ActionÒ TÒ 2Ò 0)[10](!edParse~ TargetTypeÒ PD~ TokenListÒ -KjPVHb87Nl0KPEwaI0S~ TargetSetÒ @{target|First Target|token_id}Ò @{target|Second Target|token_id}Ò @{target|Third Target|token_id}Ò @{target|Forth Target|token_id}Ò @{target|Fifth Target|token_id}Ò @{target|Sixth Target|token_id}Ò @{target|Seventh Target|token_id}Ò @{target|Eighth Target|token_id}Ò @{target|Ninth Target|token_id}Ò @{target|Tenth Target|token_id}~ ActionÒ TÒ 2Ò 0)}}" Now the weird thing is that the chat buttons always appear, but sometimes the console log errors appear, and sometimes they don't. And sometimes the buttons don't work right. So it might be an intermittent error that sometimes nothing appears in the console log, and the buttons all work. And sometimes something appears in the console log, and not all the buttons work. Or something like that.  I guess I just need to dive deeper, but thanks for putting me on track of the  character "target".
1508977812
The Aaron
Pro
API Scripter
Oh yeah, that's rife with @{target} calls.  You'll need to escape those.  I use this function: const HE = (() => {     const esRE = (s) => s.replace(/(\\|\/|\[|\]|\(|\)|\{|\}|\?|\+|\*|\||\.|\^|\$)/g,'\\$1');     const entities = {         '<' : '&'+'lt'+';',         '>' : '&'+'gt'+';',         "'" : '&'+'#39'+';',         '@' : '&'+'#64'+';',         '{' : '&'+'#123'+';',         '|' : '&'+'#124'+';',         '}' : '&'+'#125'+';',         '[' : '&'+'#91'+';',         ']' : '&'+'#93'+';',         '"' : '&'+'quot'+';'     };     const re = new RegExp(`(${Object.keys(entities).map(esRE).join('|')})`,'g');     return (s) => s.replace(re, (c) => (entities[c] || c) ); })(); Just call HE() on what you're putting in the button and it should work.