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

Can you read the pixels per cell of the current map?

I have some macros tied to spells that drop templates/tokens on a map to show where a spell effect is taking place. Suddenly, my DM threw me for a loop by changing the pixels per cell (see image below.) I scrambled to the api and cut all my pixels sizes in half, but the next time he changes map settings, they will all be askew again. Is there a way to read the pixels per cell so I can just put that in a variable and multiply it by the number of cells I want the image to take up? Or is there a way to set my tokens to the number of cells instead of the number of pixels? I'm currently using code like this: &nbsp;on("chat:message",function(msg){ &nbsp; &nbsp; &nbsp; &nbsp; if(msg.type=="api" &amp;&amp; msg.content.indexOf("!Cloud")==0) &nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var selected = msg.selected; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (selected===undefined) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat("API","Please select a character."); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var tok = getObj("graphic",selected[0]._id); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var character = getObj("character",tok.get("represents")); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var playerlist = character.get("controlledby") &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; createObj("graphic",{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; left:tok.get("left")+158, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; top:tok.get("top")+18, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height:280, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width:280, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pageid:tok.get("pageid"), &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layer:"objects", &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; imgsrc:" <a href="https://s3.amazonaws.com/files.d20.io/images/284394488/4shfVy92PYVnyR0AiZ74_A/thumb.png?16521254105" rel="nofollow">https://s3.amazonaws.com/files.d20.io/images/284394488/4shfVy92PYVnyR0AiZ74_A/thumb.png?16521254105</a> ", &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name:tok.get("name") + "'s Cloud", &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; controlledby:playerlist &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; spawnFx(tok.get("left")+140,tok.get("top"),"burst-acid",tok.get("pageid")); &nbsp; &nbsp; &nbsp; &nbsp; }
1669647167
timmaugh
Pro
API Scripter
Hey, Melvin... Yes, you can read the snapping_increment of the current page and divide it into 70 (Roll20's default for pixels-per-square). Something like: let tok = getObj('graphic',selected[0]._id); let pg = getObj('page', tok.get('pageid')); let sqpix = 70/(pg.get('snapping_increment') || 1); Then you can just multiple the sqpix variable by the number of squares you want to move in whatever direction, and do math to offset from your point of origin.
thanks timmaugh - I'll give that a shot!
1669653165
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
HI Melvin the Mediocre! I'd use a token mod command rather than re-invent the wheel. Token mod allows you to specify size by units, as well as pixels and other measurements. A fireball set for width|8u height|8u should size properly regardless of the Cell Width.
1669654497
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
And Spawn Default Token would create the object for you.
I'm doing quite a bit with the tokens, and learning to code as well but thanks for the suggestion. Timaugh got it working for me.
1669660740
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Excellent! We need more coders!