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

calling roll in sheet from an api script

1607801127

Edited 1607801163
Hi I want to make a call in my api script to use a roll from a character sheet. I use  sendChat(msg.who, text); where text is generated in the api script and looks like this: @{charactersName|rollSomething} The way via sendChat brings an error:  SyntaxError: Expected "[" or [ |\t] but "?" found. undefined But when I copy the text from my logs to the chat it works fine.
I'm not a scripter, but if you can post more of your script and the character sheet you'll probably get a more detailed answer from others who are more knowledgable than me. But I'm pretty sure  @{charactersName|rollSomething}  will not call for a roll, but an attribute reference.  For a roll you'll need  %{charactersName|rollSomething} . 
1607803216
Jordan C.
Pro
API Scripter
Yeah, if you can show exactly what the string is that you are sending a bit of the code it will help.
Here is my code: on("chat:message", function(msg) {     if (msg.type == "api" && msg.content.indexOf("!attribut ") !== -1) {         //-------------------------------------------------------------------------------         // Parameter zerlegen         // !attribut Name#?{Attribut|Charisma,CHA|Geschicklichkeit,DEX|Verstand,MIN|Geist,SPI|Stärke,STR}         //-------------------------------------------------------------------------------         var command   = msg.content.replace("!attribut ", "");         var teile     = command.split('#');         var wer       = teile[0];         var was       = teile[1];         var text = "@{" + wer + "|roll" + was + "}";         log("text=" + text);         sendChat(msg.who, text);     } }); I tried % instead of @ as suggested by Jarren. There is no error message if I do so. But in chat only the text charactersName|rollSomething is shown instead of doing the roll. @Jarren: If I type @{charactersName|rollSomething} in the inputfield of the roll20 chat the roll is done. I think attributes with names starting with roll are interpreted in a different way if there is a button with type="roll" and the right name in the sheets html. The sheet I am using is the TORG Eternity sheet. A string doing fine in chat but not via sendChat was "@{Pater Alejandro Reyes|rollCHA}".
1607874689

Edited 1607876029
Jordan C.
Pro
API Scripter
As I understand it, you cannot sendChat using the UI version of the input through the api. I believe you need to do something like this  let char = findObjs({ type: 'character', name:'TestChar', }); let rollCha = findObjs({ type: 'attribute', name: 'rollCHA', characterid: char[0].id }); Where TestChar would be the received name. From there you can get the string version of the input with something like "str = rollCha[0].get('current')". I believe you'll find more information about what you are doing here . I would have to tinker more to determine what next to with the attribute to send it into chat properly but this is a start. But also there's a lot more people who are smarterer than me that might be able to chime in. Edit: I believe getAttrByName might also be an option if there's nothing being manipulated.
Thank you very much. With your help I got a long hard to read command which I could modify to do everything I wanted to do with my API script. Best thing is: All I am using now is just a long macro, no API is needed.
1607887746
Jordan C.
Pro
API Scripter
Oh even better!