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

Init re-order button

Could someone give me a macro that re-orders the current init in a descending order, as if I had hit that button.  I have found a few but none of them seem to work and they are all over a year old, or they are part of a bigger thing that I don't want. Many Thanks.
There isn't a way unless you use an API script.
Thats what I want :)
1468214931
Lithl
Pro
Sheet Author
API Scripter
on('chat:message', function(msg) { if (msg.type !== 'api' || msg.content !== '!sort') return; let order = Campaign().get('turnorder'); if (order.length) { order = _.sortBy(order, (t) => -parseInt(t.pr)); } Campaign().set('turnorder', order); }); Execute with !sort
Doesn't do anything? Copied as listed to a new macro screen, saved it. Everything looks to load ok. Used !sort but it does nothing...
1468228004

Edited 1468228312
That's an api code, that needs to be saved as a new script in there.
Yes that is what I did, sorry I use the macro word interchangeably.  I put it into a new .js script then loaded it without errors. But the command word doesnt trigger any changes.
Ok so it turns out I need it to be ascending, RQ you add Strike Ranks... been a while :)
1468250602
Lithl
Pro
Sheet Author
API Scripter
To change the above to be ascending, change "-parseInt" to "parseInt"
Brian.  I can still not get it to work.  I have pasted it into a new .js script window, saved and restarted. Gone to the game and tried it as a chat command, and as a macro, but it does nothing. The turn order remains unchanged.   Hmm, now it is saying there is an illegal return statement?
1468279137
Lithl
Pro
Sheet Author
API Scripter
Sorry, I forgot that let  is a strict-mode-only keyword, and I forgot the parse/stringify the turn order. Try this one: on('chat:message', function(msg) {     'use strict';     if (msg.type !== 'api' || msg.content !== '!sort') return;     let order = Campaign().get('turnorder');     if (order.length) {         order = _.sortBy(JSON.parse(order), (t) => -parseInt(t.pr));     }     Campaign().set('turnorder', JSON.stringify(order)); }); (Swapping -parseInt for parseInt as needed to get the ordering you're looking for)
Still getting an illegal return statement...
OK I got it working, put it into an exist script I had and adjusted and now looks good, just hope it doesnt break something else... :) Thank you.
However, because I am using a decimal place for init, eg 7.3 or 7.4 it lists the decimals in the wrong order... eg 7.2 7.3 7.4 would be listed as 7.4 7.3 7.2... is there something to adjust this.  Worst case I can run i the other way and its correct, but in a reverse usage.
1468301793
Lithl
Pro
Sheet Author
API Scripter
Change parseInt to parseFloat