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

Checking new tokens to see if they're dice tokens

1699914863
Rich R.
Marketplace Creator
Sheet Author
Compendium Curator
I'm making a script that sets dice tokens (the ones dragged onto the table from chat) to be controlled by all players. What I have so far is just listening to `add:token` and setting `controlledby`. on('add:token', tok=&gt;{ tok.set('controlledby', 'all') }) ...that works fine, but it changes all &nbsp;tokens on creation. Ideally, I'd like to look for some property of `tok` in there to only do this for dice tokens, but I'm not sure what to check for on those objects. I'm seeing some consistent portions of the `imgsrc` and `sides` properties, but I'm not sure if those will be reliable between games, pages, etc. { "_id": "-Nj9Konx97GwuoWRrQRd", "_pageid": "-Nj4peOfoo40_aom8KKr", "left": 872, "top": 115, "width": 70, "height": 70, "rotation": 0, "layer": "objects", "isdrawing": true, "imgsrc": "<a href="https://s3.amazonaws.com/files.d20.io/images/779535/vkc_PT4z-d_ON1MvfHaCiA/thumb.png?1363049999" rel="nofollow">https://s3.amazonaws.com/files.d20.io/images/779535/vkc_PT4z-d_ON1MvfHaCiA/thumb.png?1363049999</a>", "sides": "https%3A//s3.amazonaws.com/files.d20.io/images/779533/-gS85HUaXIvmE5SjGpoH4w/thumb.png%3F1363049998|\ https%3A//s3.amazonaws.com/files.d20.io/images/779535/vkc_PT4z-d_ON1MvfHaCiA/thumb.png%3F1363049999|\ https%3A//s3.amazonaws.com/files.d20.io/images/779534/mHDadFirie4L12_ii-HYqQ/thumb.png%3F1363049998|\ https%3A//s3.amazonaws.com/files.d20.io/images/779531/nXqp2BhdwVsQn7cDR3cMlg/thumb.png%3F1363049998|\ https%3A//s3.amazonaws.com/files.d20.io/images/779532/nQD5_IXYLWN7YCjnd5zugA/thumb.png%3F1363049998|\ https%3A//s3.amazonaws.com/files.d20.io/images/779536/ttiwwiWE2PVkhD2d7fV3GA/thumb.png%3F1363049999", "currentSide": 1, "_type": "graphic", "_subtype": "token", "_cardid": "", } Anyone know if there's a definitive property I could look for that tells me "this is definitely a dice token?"
1699915851
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Hi Rich! Give me the URL of a die size and side, and I will tell you if it matches one I generate in my own game.
1699917849
Rich R.
Marketplace Creator
Sheet Author
Compendium Curator
keithcurtis said: Hi Rich! Give me the URL of a die size and side, and I will tell you if it matches one I generate in my own game. Thanks! This is a subset of properties from a d6 showing 3 that I just dragged out of chat (I added line breaks in `sides` for legibility): { &nbsp; &nbsp; "_id": "-Nj9yWxhVCmrgkOQbcq9", &nbsp; &nbsp; "_pageid": "-Nj4peOfoo40_aom8KKr", &nbsp; &nbsp; "left": 506, &nbsp; &nbsp; "top": 450, &nbsp; &nbsp; "width": 70, &nbsp; &nbsp; "height": 70, &nbsp; &nbsp; "rotation": 0, &nbsp; &nbsp; "layer": "objects", &nbsp; &nbsp; "isdrawing": true, &nbsp; &nbsp; "flipv": false, &nbsp; &nbsp; "fliph": false, &nbsp; &nbsp; "imgsrc": "<a href="https://s3.amazonaws.com/files.d20.io/images/779534/mHDadFirie4L12_ii-HYqQ/thumb.png?1363049998" rel="nofollow">https://s3.amazonaws.com/files.d20.io/images/779534/mHDadFirie4L12_ii-HYqQ/thumb.png?1363049998</a>", &nbsp; &nbsp; "sides": "https%3A//s3.amazonaws.com/files.d20.io/images/779533/-gS85HUaXIvmE5SjGpoH4w/thumb.png%3F1363049998|\ &nbsp; &nbsp; https%3A//s3.amazonaws.com/files.d20.io/images/779535/vkc_PT4z-d_ON1MvfHaCiA/thumb.png%3F1363049999|\ &nbsp; &nbsp; https%3A//s3.amazonaws.com/files.d20.io/images/779534/mHDadFirie4L12_ii-HYqQ/thumb.png%3F1363049998|\ &nbsp; &nbsp; https%3A//s3.amazonaws.com/files.d20.io/images/779531/nXqp2BhdwVsQn7cDR3cMlg/thumb.png%3F1363049998|\ &nbsp; &nbsp; https%3A//s3.amazonaws.com/files.d20.io/images/779532/nQD5_IXYLWN7YCjnd5zugA/thumb.png%3F1363049998|\ &nbsp; &nbsp; https%3A//s3.amazonaws.com/files.d20.io/images/779536/ttiwwiWE2PVkhD2d7fV3GA/thumb.png%3F1363049999", &nbsp; &nbsp; "currentSide": 2, } I suspect that the numbers `779531` through `779536` might be consistent representations of the six sides of a d6, but that's just a hunch.
1699921187
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
My image address for a 1 on a d6 is: <a href="https://files.d20.io/images/779533/-gS85HUaXIvmE5SjGpoH4w/original.png?13630499985" rel="nofollow">https://files.d20.io/images/779533/-gS85HUaXIvmE5SjGpoH4w/original.png?13630499985</a> That might be due to the age of my game. Newer games might be using the s3 address. but the rest is the same (you can ignore the 11 digit cache buster) Checking: Nope, a newer game also gives me an address of <a href="https://files.d20.io/images/779533/-gS85HUaXIvmE5SjGpoH4w/original.png?136304999855" rel="nofollow">https://files.d20.io/images/779533/-gS85HUaXIvmE5SjGpoH4w/original.png?136304999855</a> It might be then due to the way I interact with Roll20's image service as a contractor?
1699921533

Edited 1699921930
My 1 on a d6 is: <a href="https://files.d20.io/images/779533/-gS85HUaXIvmE5SjGpoH4w/original.png?13630499985" rel="nofollow">https://files.d20.io/images/779533/-gS85HUaXIvmE5SjGpoH4w/original.png?13630499985</a> I am not using the " Use Experimental Image Delivery Service", I wonder if that affects the image URLs? EDIT: Ah ok copying the URL of the image gets you the above URL. If you use the console to get the token information you get a different URL; " imgsrc" property on the d6 token is: <a href="https://s3.amazonaws.com/files.d20.io/images/779533/-gS85HUaXIvmE5SjGpoH4w/thumb.png?136304999" rel="nofollow">https://s3.amazonaws.com/files.d20.io/images/779533/-gS85HUaXIvmE5SjGpoH4w/thumb.png?136304999</a>
1699927503
The Aaron
Roll20 Production Team
API Scripter
The files.d20.io and s3.amazonaws.com URLs are basically the same. The files one is newer and faster, but the API can only create the AWS one (so api scripts currently have to do a string replace to get a valid url)
1699936791
Rich R.
Marketplace Creator
Sheet Author
Compendium Curator
Cool, thank you both for checking that...it looks like the six-digit number in the middle does signify the six sides of the die. And despite being sequential numbers, they don't correlate to the sides in order. I should be able to just regex for those.