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

Organizing Abilities Easily

I've been looking around the forums for a bit trying to find a way to automatically alphabetize my macro mule's Abilities list. There's a post here from 3 years ago by The Arron that gives a javascript on how to do it, but I don't know how to incorporate that script into an API or wherever it needs to go. There's a video here by Nick that goes into importing and exporting macros using an API to create a character who holds all the macros and that's in alphabetical order,  but when I ran the script my abilities were out of order. I feel like there's a step that I can do where I organize the array and THEN slap it onto a character, but I'm not sure how to do that. All help is appreciated. This is like #12 on my todo list and it's holding up much bigger and more time sensitive things, but I can't let it go. Thank you!
Ooh, interesting. I, too, would like to know this.
1651560266
The Aaron
Roll20 Production Team
API Scripter
What I posted 3 years ago just does it in the current browser window, not permanently. 
1651588574
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Also, last I checked, Chrome now disallows running JavaScript applets in the URL of the browser, and has done so for a few years. I think they can still be run on Firefox, but I haven't checked recently.
1651654651

Edited 1651674367
Oosh
Sheet Author
API Scripter
edit - never mind this, it doesn't do any more than Aaron's scriptlet. The post below does a permanent change, though. Brief description: firebase doesn't allow for re-ordering of database documents, as it's antithesis to the design. You're supposed to handle ordering on a document query, not rewrite the whole database every time you want stuff in a different order. Characters have an attribute which stores the query order (much like repeating sections on a character sheet have a _reporder), which is unfortunately not exposed to the API. Not sure why, it's not like we can't already brick a character by destroying the Attributes, may as well let us at the abilities! You can do this via the browser console. Bear in mind that changes made this way are permanent, so if anything goes wrong you're stuck with it, including a bricked character. I can't see how sort() would destroy an Array, but I would do this with a duplicate character anyway. If you paste this function into the console: const sortAbilities = (charName) => { Campaign.characters.find(c=>c.get('name') === charName).abilities.models = Campaign.characters.find(c=>c.get('name') === charName).abilities.models.sort((a,b) => a.get('name') > b.get('name')) } You can run it with an exact name match. There's no error handling, it'll just error out if the charName is not found. sortAbilities('Alice'); You'll need to re-open the sheet to see the changes. This is a simple charCode sort - you'll need a more sophisticated predicate function if you want lowercase and UpperCase to be mingled together.
1651673531
Oosh
Sheet Author
API Scripter
Paste this into console, instead of the above: const sortAbilities = ( charName ) => {   const char = window . Campaign . characters . find ( c => c . get ( 'name' ) === charName );   if (! char ) return ;   const sortAlphabeticalById = ( charRef ) => {     const charAbilities = charRef . abilities . models ;     const newAbilityOrder = charAbilities . sort (( a , b ) => a . get ( 'name' ) > b . get ( 'name' ));     return newAbilityOrder . map ( a => a . id );   }   const newIdArray = sortAlphabeticalById ( char );   console . log ( newIdArray );   char . save ( 'abilorder' , newIdArray . join ( ',' )); } And then run it with an exact character name match: sortAbilities ( 'Alice' ); Same caveat as above - this is a simple sort by ascii code, so Zebra will come before aardvark. You can chuck a more sophisticated sort predicate in there to ignore uppercase, prioritise certain character or numbers, or what have you.
To run it in the console, I have to make it a script, right? The name of the character I'm trying to do this to is "Macros", so does the code look like this? on( "ready", function(){   sortAbilities('Macros'); const sortAbilities = (charName) = > {   const char = window.Campaign.characters.find(c = >c.get('name') === charName);   if (!char) return;   const sortAlphabeticalById = (charRef) = > {     const charAbilities = charRef.abilities.models;     const newAbilityOrder = charAbilities.sort((a , b) = > a.get('name') > b.get('name'));     return newAbilityOrder.map(a = >a.id);   }   const newIdArray = sortAlphabeticalById(char);   console.log(newIdArray);   char.save('abilorder' , newIdArray.join(' , ')); }})