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

[Sticky Suggestion] Would like to suggest two new stickies....

1428165103

Edited 1428165942
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
Would like to suggest two new stickies.... 1) Recommended Common Code Snippets This is a "locked" thread that only Aaron adds post to. An unindexed list of code snippets that will one day find their way to the wiki or are just really useful discovered or clever examples of code. Example: fixedRotaion = fixAngle(obj.get("rotation")) //fixes a tokens rotation value to nearest degree of: 0,45,90,135,180,225,270, or 315 fixAngle = function(angle){ return (Math.round(angle/45)*45)%360 + (angle<0 ? 360 : 0); }, Another one that would have been here is the "fixnewobject" one we were all using. 2) Suggested Common Code Snippets This is a unlocked thread to argue about what should go into "Recommended Common Code Snippets." Might be good ideas here, however for whatever reason they are not recommended (to specialized, to large, to "whatever.") The creator (or co-creators) would be responsible for making a clear code snippet to go into the "Recommended Common Code Snippets." (So Aaron only has to copy and paste.) I know this could be a lot of work for Aaron, however I am ok with that.
1428170177
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
flipGraphic(obj,'H') or flipGraphic(obj,'V') //toggles the true/false setting for a graphics fliph property or flipv property flipGraphic = function(graphic, direction) { graphic.set({ fliph: 'H' === direction ? !graphic.get('fliph') : graphic.get('fliph'), flipv: 'H' !== direction ? !graphic.get('flipv') : graphic.get('flipv') }); }
1428171999
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
Or this one.... <a href="https://app.roll20.net/forum/post/1517881/pathfind" rel="nofollow">https://app.roll20.net/forum/post/1517881/pathfind</a>... Dozens of little gems out there which are worth collecting in one thread.
Less stickies!! I use the 'all discussions' link to browse the forum all the time and there are way too damn many sticky threads.
1428234545
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
HoneyBadger said: Less stickies!! I use the 'all discussions' link to browse the forum all the time and there are way too damn many sticky threads. Good point. We could kill and replace <a href="https://app.roll20.net/forum/post/210894/scripts-a" rel="nofollow">https://app.roll20.net/forum/post/210894/scripts-a</a>... We shouldn't need that one any more.. use it for: "1) Recommended Common Code Snippets." The other one doesn't need to be sticky.
1428240057
The Aaron
Pro
API Scripter
Probably the wiki is a better place for this. :)
1428244683
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
The Aaron said: Probably the wiki is a better place for this. :) We have a Wiki? :)
1428247947
The Aaron
Pro
API Scripter
Trolled again... <a href="https://wiki.roll20.net/API:Cookbook" rel="nofollow">https://wiki.roll20.net/API:Cookbook</a>
1428249376
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
The Aaron said: Trolled again... <a href="https://wiki.roll20.net/API:Cookbook" rel="nofollow">https://wiki.roll20.net/API:Cookbook</a> So... been looking at status markers. Wiki Cookbook Status stuff. on that topic: here. I just want to know if the "green dot is on or off (regardless on the number.) selectedGreen = false === selected.get('status_green') ? false : true; Most people don't use the "#" too much and I don't care if they do, I just want to know off or on (whatever the number). Is that worth tucking it into the wiki?
1428255922
The Aaron
Pro
API Scripter
You can simplify that since the === returns either true or false, and you want false or true. Adding ! reverses the boolean. You can either surround the whole expression and use !( &lt;expression&gt;) or just use !== instead of === to reverse the case during the comparison: selectedGreen = false !== selected.get('status_green'); Could be worth adding.
1428257592
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
Yea, those status icons can be a head scratcher... for me at least. You think in terms of "true" "false"... the little green dot is on or the little green dot is off. But someone could sneak in '2" in place of true.... and you just wanted all cases of green dot on is "true." Also status icons are going to be all the rage when we can create our own.
1428259437
The Aaron
Pro
API Scripter
Some more equivalent options option is: // Using !! to coerce a boolean out of the returned array selectedGreen = !! selected.get('statusmarkers').match(/\bgreen\b/); // testing the regular expression against the status markers selectedGreen = /\bgreen\b.test(selected.get('statusmarkers')); // building the regular expression dynamically var color = 'green'; var greenMatcher = new RegExp('\\b'+color+'\\b'); selectedGreen = greenMatcher.test(selected.get('statusmarkers'));
1428260180
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
I like the last one.... Couldn't I do this then? var isGreen = hasStatus('green', selected); hasStatus = function(status, selected) { var statusMatcher = new RegExp('\\b'+status+'\\b'), foundStatus = statusMatcher.test(selected.get('statusmarkers')); return foundStatus; },
1428262236

Edited 1430594603
The Aaron
Pro
API Scripter
Yes! (But JSLint & Dougie C. would complain about you using the function before it had been defined! =D ) I'd probably write that as: // escape all the characters in a string that need to be escaped for Regular Expressions var esRE = function (s) { var escapeForRegexp = /(\\|\/|\[|\]|\(|\)|\{|\}|\?|\+|\*|\||\.|\^|\$)/g; return s.replace(escapeForRegexp,"\\$1"); }, hasStatus = function (status, selected) { return ( new RegExp('\\b'+esRB(status)+'\\b') ).test( (selected && selected.get && selected.get('statusmarkers')) || '' ); };
1428264398
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
+1
1428811676
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
So.... Been playing around with events a lot lately. Why not capture some common used things on event all the time. Then if you write a "!get HP" script, you will already have the last changed value of HPs.
1429783497
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
objExtractKeys = ['id','pageid','stroke','rotation','layer','width','height','top','left','controlledby'], getObjValue = function(obj, keys) { return _.reduce( keys || objExtractKeys, function(m,prop){ m[prop] = obj.get(prop); return m; }, {}); }, doSomething = function(obj) { var ObjValues = getObjValue(obj); log(ObjValues.id) }, That was a handy bit of code you gave me Aaron!
1429815292
The Aaron
Pro
API Scripter
no problem! =D
1430231140
The Aaron
Pro
API Scripter
Here's a small function I wrote for removing a token's turn from the turn order: var removeTurn = function (tokenID){ "use strict"; Campaign().set({ turnorder: JSON.stringify( _.reject( (JSON.parse(Campaign().get('turnorder'))||[]), function(to){ return to.id === tokenID; }) ) }); };
1430231677
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
One these small functions.. would it be better to alays pass the object? I know its a small thing, but then you know you are always going to pass the Roll20 object. var removeTurn = function (graphic){ "use strict"; var tokenID = getObjValue(obj).id; Campaign().set({ turnorder: JSON.stringify( _.reject( (JSON.parse(Campaign().get('turnorder'))||[]), function(to){ return to.id === tokenID; }) ) }); };