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

[Script] Sort Tables

1607968251

Edited 1607975292
Jordan C.
Pro
API Scripter
Hola, I don't know how usefully this will be for anyone else, but I started working on a table sorting script for rollable tables. I have gotten pretty far in terms of error handling but I would really appreciate some help trying to break this thing. If you would like to, please do so in a copy of a game or test environment. I cannot stress enough how much I do not recommend testing this in a game that you do not want potential data loss. Also, in an effort to keep the commands congruent with a lot of Aaron's scripts I have used similar input handling and shamelessly recycled the entire switch from one of his scripts (as always, thank you Aaron). DISCLAIMER: This script deletes and renames tables during the process. Install at your own risk. This is very much a WIP. I am attempting to make sure the delete command cannot function accidentally. Here is how the chat commands would typically go: "!sort-tables --tag" : this will rename all current tables with a leading !SRC! tag (e.g. "Wild-Magic" becomes "!SRC!Wild-Magic" "!sort-tables --create": this creates new JS objects from any table that was tagged, sorts them, then creates Roll20 objects in that order and tags them with a leading "!SORTED!" tag (e.g. new table is created title "!SORTED!Wild-Magic". "!sort-tables --delete" "--source": this deletes all tables tagged with "!SRC!". This process will be cancelled if the number of source tagged tables equals the amount of tables in the game (i.e. you cannot delete tables if the end result would be no tables left in the game). This is an effort to prevent the delete action from being used before the new tables are created. "--sorted": same thing but deletes tables tagged with "!SORTED!" "!sort-tables --remove" " --sorted": this removes all "!SORTED!" tags from the leftover tables. You cannot perform this command unless there are two sets of matching tables where one set is tagged with source and the other tagged with sorted. You can override this by adding "--force" to the end of the command. This is to prevent tags being removed without confirmation from the user since it will prevent the sorted tables from being deleted if there happened to be an error. "--source": same thing but for tables tagged with "!SRC!" If you have any &nbsp;ideas/criticisms/improvements I am very interested in hearing them. If the tagging could be handled better, the error handling, etc. I am by no means a professional and am super prone to tunnel visioning after staring at this for so long. So please break this thing in a safe, testing envrionment. Right now, the script is intended to only sort tables alphabetically. I would love to expand the functionality of that to sort by other parameters or even group tables based on whether or not they have avatar items so that token tables can by grouped separately from regular rollable tables. Before I can do that though, I want to make this thing as bulletproof as possible so that it doesn't cause irreparable damage. For that reason, I also won't be submitting this script to One-Click so it will need to be manually installed. You can find the script here: <a href="https://github.com/JWCaiola/TableSorting/blob/master/TableSorting.js" rel="nofollow">https://github.com/JWCaiola/TableSorting/blob/master/TableSorting.js</a>
1607968981
The Aaron
Roll20 Production Team
API Scripter
(To be fair, I stole that syntax from Honey Badger originally, so feel free!) This is a great idea!&nbsp; One thing to look out for is going to be Marketplace Images in the Table Item avatar, as the API won't be able to recreate those. (you may have handled that already, I've not looked yet...)
1607969948

Edited 1607970015
Jordan C.
Pro
API Scripter
I have not handled that: the img src stuff eludes me a bit to be honest, and I tried to find a way to check if the image exists in the users library to no avail. If I can add something to catch an instance of art that is unavailable to recreate I would love to add that.
1607970108
The Aaron
Roll20 Production Team
API Scripter
Give this a try:&nbsp; <a href="https://wiki.roll20.net/API:Cookbook#getCleanImgsrc" rel="nofollow">https://wiki.roll20.net/API:Cookbook#getCleanImgsrc</a>
1607970245
Jordan C.
Pro
API Scripter
The Aaron said: Give this a try:&nbsp; <a href="https://wiki.roll20.net/API:Cookbook#getCleanImgsrc" rel="nofollow">https://wiki.roll20.net/API:Cookbook#getCleanImgsrc</a> Amazing, I need to work on my google-fu. Thanks!
1607971637
The Aaron
Roll20 Production Team
API Scripter
Hahahahah, well, having written it, I knew where to look. ;D