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

Is There an Error in API: Advanced User Guide: A Note on Utility Functions?

1594404368

Edited 1594404766
After a question I posed I found the above page, API: Advanced User Guide , at <a href="https://roll20.zendesk.com/hc/en-us/articles/360037772773" rel="nofollow">https://roll20.zendesk.com/hc/en-us/articles/360037772773</a> and have begin going through it to better understand things. I would very much appreciate it if any reader could please let me know if I have stated my problem clearly or if I am talking like a babbling brook.&nbsp; :) Thanks in advance! I've been copying code to a script I've called "Learning.js".&nbsp; When I tried the code listed under A Note on Utility Functions , which uses the "distanceToPixels" function, it threw an error when compiling (I assume "compiling" is the correct term?).&nbsp; See: <a href="https://roll20.zendesk.com/hc/en-us/articles/360037772773#API:AdvancedUseGuide-ReactiveScripts:ListentoEvents,ModifyObjects" rel="nofollow">https://roll20.zendesk.com/hc/en-us/articles/360037772773#API:AdvancedUseGuide-ReactiveScripts:ListentoEvents,ModifyObjects</a> Note that distanceToPixels() is used the script, but the text of the link refers to " distanceToPixelsfunction ".&nbsp; Not sure if that's an error. Here is a screenshot the console error message I am receiving: Here is what is listed in the Learning.js script as copied from the previous link on the API: Advanced User Guide: A Note on Utility Functions page and section: on( "change:graphic" , function ( obj ) { obj.set({ left : obj.get( "left" ) + distanceToPixels( 5 ); }); }); And here it is on my console.&nbsp; I have circled a semicolon.&nbsp; when I remove that, my sandbox compiles correctly and things work on my desktop when I launch the game.&nbsp; However, see my notes following the screenshot, below: When I remove the semicolon circled in red on the above screen shot, my sandbox compiles correctly.&nbsp; When I launch the game, my previously written macros work correctly.&nbsp; However, nothing appears to happen when I move or alter a character object on the table top.&nbsp;&nbsp; My hexagons are 70 pixels across and represent 2 kilometres.&nbsp; The commented out script in the above screen shot worked properly made for lots of delighted amusement when I saved it previously and :)&nbsp; is from the first script shown on the API: Advanced User Guide in the section immediately preceding. Changing the distanceToPixels(5) to distanceToPixels(20) caused an error in compilation. So, is there some kind of error when in the link's code?&nbsp; I hope I have explained my question clearly. Thanks in advance, and all the best, -- Tim
1594405255

Edited 1594405424
The Aaron
Roll20 Production Team
API Scripter
The code should be: on( "change:graphic" , function ( obj ) { obj.set({ left : obj.get( "left" ) + distanceToPixels( 5 ) }); }); There's an errant ; in the set call that must be removed.&nbsp; Possibly I missed the point of the question. =D What are you asking?
The Aaron said: The code should be: on( "change:graphic" , function ( obj ) { obj.set({ left : obj.get( "left" ) + distanceToPixels( 5 ) }); }); There's an errant ; in the set call that must be removed. Thank you, once again, for the help. :) Possibly I missed the point of the question. =D What are you asking? God knows, it was 26 minutes ago (19 after all the edits).&nbsp; How can I be expected to remember back that far?&nbsp; LOL In all seriousness, can you tell me what distancetopixels(5) does and why did it vomit when I changed the 5 to a 20?
1594413427
The Aaron
Roll20 Production Team
API Scripter
I have a vague notion that I tried it 5+ years ago. No idea why it broke, but I speculate it's not used by anyone. In its current form, it can't possibly work correctly. What it should do, and what you would do, is find the page and get snapping_increment and scale_number. Then take the (distance/scale_number)*(70/snapping_increment) do find how many pixels that distance is. The reason the function can't possibly work is that it doesn't know what page you're asking about.&nbsp;
The Aaron said: I have a vague notion that I tried it 5+ years ago. No idea why it broke, but I speculate it's not used by anyone. In its current form, it can't possibly work correctly. What it should do, and what you would do, is find the page and get snapping_increment and scale_number. Then take the (distance/scale_number)*(70/snapping_increment) do find how many pixels that distance is. The reason the function can't possibly work is that it doesn't know what page you're asking about.&nbsp; Wilco, thank you very much.