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

DM Dashboard - Beta (Turnorder on Steroids for D&D 5e Roll20 based games)

1684248410
The Aaron
Roll20 Production Team
API Scripter
Mod Scripts can't determine the validity of an image URL.  You can use this function to get back an image src that Mod scripts can manipulate (basically, it must be 1) in a User Library, and 2) the `thumb` version.): const getCleanImgsrc = (imgsrc) => { let parts = (imgsrc||'').match(/(.*\/images\/.*)(thumb|med|original|max)([^?]*)(\?[^?]+)?$/); if(parts) { return parts[1]+'thumb'+parts[3]+(parts[4]?parts[4]:`?${Math.round(Math.random()*9999999)}`); } return; };
Handy, I'll definitely use it.
1684255498

Edited 1684255758
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
You might want to look at the Campaign Survey script to see if you can find any useful ideas for Player Access report .
That's one of the scripts I peruse quite often for techniques and ideas.  Good suggestion. keithcurtis said: You might want to look at the Campaign Survey script to see if you can find any useful ideas for Player Access report .
I've posted my 0.0.01 version of my new CampaignHealth script&nbsp; to my GitHub.&nbsp;&nbsp; <a href="https://github.com/MadCar-Dev/Default/blob/af21dd10ae88a253018a65bca6252c068f759a41/Javascript/CampaignHealth.js" rel="nofollow">https://github.com/MadCar-Dev/Default/blob/af21dd10ae88a253018a65bca6252c068f759a41/Javascript/CampaignHealth.js</a> Chat command:&nbsp; !campaignhealth produces two handout reports: 1. Campaign Health - Tests your campaign for common issues like orphaned records, duplicate characters and tokens that have fallen off the page.&nbsp;&nbsp; 2. Player Access - Summary of all the objects players have access to Note: If you run this on a large campaign, it could take about 20 to 30 seconds to run.&nbsp;&nbsp;
1684262390
The Aaron
Roll20 Production Team
API Scripter
You should get in the habit of wrapping your whole script in the on('ready',...) closure.&nbsp; Basically, move line 12 all the way to the bottom. Speaking of the bottom, you're missing the closing half of API_Meta.&nbsp; See:&nbsp;<a href="https://app.roll20.net/forum/post/9771314/script-apilogic-gives-if-slash-elseif-slash-else-processing-to-other-scripts/?pageforid=9772430#post-9772430" rel="nofollow">https://app.roll20.net/forum/post/9771314/script-apilogic-gives-if-slash-elseif-slash-else-processing-to-other-scripts/?pageforid=9772430#post-9772430</a>
Yep - forgot the API_Meta footer logic.&nbsp; &nbsp;For some reason, I didn't realize you could place the other "On Event" functions inside of the On Ready function.&nbsp;&nbsp; Appreciate your mentorship.&nbsp; I've made the changes and republished it.&nbsp; The Aaron said: You should get in the habit of wrapping your whole script in the on('ready',...) closure.&nbsp; Basically, move line 12 all the way to the bottom. Speaking of the bottom, you're missing the closing half of API_Meta.&nbsp; See:&nbsp; <a href="https://app.roll20.net/forum/post/9771314/script-apilogic-gives-if-slash-elseif-slash-else-processing-to-other-scripts/?pageforid=9772430#post-9772430" rel="nofollow">https://app.roll20.net/forum/post/9771314/script-apilogic-gives-if-slash-elseif-slash-else-processing-to-other-scripts/?pageforid=9772430#post-9772430</a>
1684266477
timmaugh
Pro
API Scripter
Scripts having the the registration of other events in the on('ready') event is what allows metascripts to do what they do. That is the difference between a standard script and a metascript. So, yes... please do nest them! =D
A couple of questions about Roll20s API. It appears that when multiple tokens are selected, and you run a script against the selected tokens, all the tokens get unselected automatically.&nbsp; This behavior is different when you only have one (1) token selected as it stays selected after you run your script against it.&nbsp;&nbsp; 1) Is there a way to stop Roll20 from unselecting multiple tokens? 2) Does Roll20 javascript support Static variables in functions? Thanks, Will M.
1684342807
The Aaron
Roll20 Production Team
API Scripter
In my experience, the deselection only happens if you make certain changes to the tokens, but that might have changed.&nbsp; I'll check after this meeting. Regarding Static variables.&nbsp; I'm assuming this is ala C++ static variables.&nbsp; The way you'd do that is via a closure: const func = (()=&gt;{ let psuedoStatic = 0; return (a,b) =&gt; { psuedoStatic = (psuedoStatic * a / b) return psuedoStatic; }; })();
I want a variable in a function to retain its value between calls to it.&nbsp; It behaves like a global variable but only exists within the scope of the function.&nbsp; Trying to avoid using Global and State variables if I don't have to.&nbsp; &nbsp;&nbsp;
1684350088

Edited 1684350262
The Aaron
Roll20 Production Team
API Scripter
yup, that's exactly what the example code will do.&nbsp; In Javascript, when you execute a function, it creates a closure, which contains all the variables created during the execution.&nbsp; You can think of it like a dynamically allocated stack frame.&nbsp; That closure is reference counted, so as soon as there are no more references to it, it goes away.&nbsp; Anything created within the closure has implicit access to it, and maintains a reference.&nbsp; The practical upshot is that when you define a function within the execution of another function (within its closure), and then return that function outside of the scope, it still maintains access to that scope, but nothing else does.&nbsp; That effectively gives it private, persistent variables that behave largely like static variables in C++. const func = (()=&gt;{ //&lt; This defines a function // inside the closure let psuedoStatic = 0; return (a,b) =&gt; { //&lt; This returns a function out of the closure psuedoStatic = (psuedoStatic * a / b) return psuedoStatic; }; })(); //&lt; this calls the first function, returning the second to be stored in the func variable This pattern is pretty common in Javascript, particularly before the introduction of classes in ES6.&nbsp; This is how the Revealing Module Pattern works, though in that case you're often returning an object and using the closure for what would be private variables in C++ (Javascript lacked a concept of private variables until very recently). The outer function, which is just responsible for setting up the closure and returning the function with access to it, is called an IIFE (if-y), or Immediately Invoking Function Expression.&nbsp; The invocation happens on the last line, with those trailing () there. One place that this technique varies from static variables in C++ is that if you kept the outer function around, you could manufacture many of the inner function, all with their own set of private variables.&nbsp; Basically a factory function.&nbsp; Here's an example: const counterMaker = () =&gt; { let n = 0; return () =&gt; ++n; }; Calling this function will return a function which returns a series of monotonically increasing integer values.&nbsp; Each time you call it, you get a new, unrelated counter.
1684353290

Edited 1684353307
Ok - Just ran a test and sure enough, variables defined at higher levels of scoping retain their values and behave like static variables.&nbsp; Another benefit of placing all your code in the On Ready event.&nbsp; This means I can drop some of the globals I previously defined down into my On Ready event and they'll persist between calls (but not restarts of the sandbox).&nbsp;&nbsp; I keep falling into the trap of thinking in terms of C++, VB,&nbsp; and Fortran (and other languages).&nbsp;&nbsp; Again - Thanks for you help.
Added Status Marker Dialog to DM Dashboard. Allows you to quickly set, unset and clear status markers (token markers) on one or more selected tokens. For example, Select 5 goblins, click the sleep marker and all 5 of the goblins will have a sleep marker appear on their thoken.&nbsp;&nbsp; You can also toggle the Mode from " Toggle On/Off " to " Increment" which incrementally adds a number to the marker, 0 through 9 (after 9, it removes the markers).&nbsp;&nbsp; Want to remove all markers from all tokens - just select all tokens on your map, and hit the clear button.&nbsp;&nbsp; This dialog is accessible from the main menu of the Turnorder Dashboard.&nbsp;&nbsp; Finally, clicking on a status marker in the Turnorder dashboard will remove the marker from the token.&nbsp;&nbsp;