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

Using the API with Tokenmod -- newbie error?

November 04 (4 years ago)

Edited November 04 (4 years ago)

Hi gang,

I'm just getting started with roll20 scripting and am trying to call tokenmod via sendChat.  A simple test I'm trying is..

sendChat("Somebody", "!token-mod --help");

... which should just display the help text in the chat output pane.

What I get in the console when that function executes is..

{"who":"error","type":"error","content":"Unable to find a player or character with name: API"}

Can any kind soul point me in the right direction?

Thanks!

Dan

November 04 (4 years ago)

Edited November 04 (4 years ago)
David M.
Pro
API Scripter

EDIT - while the below is usually required, I missed that he was just using --help, which doesn't need a selected token

Token-mod defaults to performing the operation on the selected token, which your script "forgets" when it is running. Try grabbing the id of the selected token from msg first, and then adding the --ids command to your token-mod call. 

November 04 (4 years ago)

Thanks for the reply.

That's odd that !token-mod --help from the chat interface does not require a selected token.  However, I took your advice and now what is being sent is,

"!token-mod --ids -MLFROlGe11G9pkg77M0 --help"

But the error still persists.

November 04 (4 years ago)

Edited November 04 (4 years ago)
David M.
Pro
API Scripter

Ah, missed that you were just calling "help". Sorry 'bout that. Error is probably because token-mod help is whispered to the player that called it. When called from the api, it is likely confused who to whisper to. 

Looked at the token-mod documentation, and this looks relevant. Try adding it to your token-mod call.

  • --api-as <playerid> -- Sets the player id to use as the player when the API is calling the script.

If this doesn't work, TheAaron or one of the other scripting gurus will probably be along sometime to set you straight. 

November 04 (4 years ago)

Let it hereby be known that I owe David M. a beer!

I totally missed that api-as option.  Like the post title said, "newbie".  Thanks so much for your help!!

Dan

November 04 (4 years ago)
David M.
Pro
API Scripter
Np, sorry for the wild goose chase initially (though hopefully it will help avoid a future problem) :)
November 04 (4 years ago)
The Aaron
Roll20 Production Team
API Scripter

David's spot on. =D  The --api-as argument is there to let a script pass along the playerid executing a command so that the permissions in TokenMod can be effective, etc.

November 04 (4 years ago)

Thanks guys!  Works like a champ now.