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

[Problem] API Not working properly with selected tokens and API commands & turnorder

I have created a script which adds selected tokens to the turnorder ( found here ), and then rolls for them based on an array of modifiers. The system works great when it actually runs. The problem that is happening requires the following: 1) the initiative pane is blank 2) I select some tokens (a mix of players and NPC tokens) 3) I run my macro (!CombatBegins) 4) Initiative begins (I know because I have a script for a timer to appear next to the active players turn), and the initiative pane appears but it blank 5) I close the initiative pane and reopen it and it is filled <== problem #1 6) I select another token not in initiative and run !CombatBegins 7) I close and open initiative pane and it is added <== problem #1 still 8) I repeat 6) a few times, at some point it stops adding them, but the rest of my scripts continue to run, suggesting its not an error in my coding I did a few tests. Before my script runs, I added log(msg), so every message I sent to the chat log would show up in the log. When the error takes place, I type !CombatBegins and nothing appears in the log. This suggests that something in the API is catching my command, but not sending it to the API. I don't know what would cause this but it did not happen with this script before the update that included the selected tokens feature. Thanks for your help!
The problem doesn't seem to be with your script, but rather the fact that the Tracker itself freezes whenever a new token is pushed (or unshifted) into the order. It also doesn't seem responsive to opening or closing on command (which may be the reason why the glitch is happening in the first place), but if you go with Campaign.set("initiativepage", true/false), it's only working about 20% of the time....
1376001597

Edited 1376002053
Thats odd because I did mine exactly the way they recommend on the wiki. I thought about trying to push them one at a time to Campaign().turnorder, but I don't know if that will work.  I will give it a shot and see. EDIT: nope. nor shift.
1376003709

Edited 1376005522
Lol, yeah, I noticed it was verbatim from the wiki. And for all intensive purposes it should work flawlessly, but once somethings pushed or shifted into the line-up, it completely freezes the tracker, you cannot change order using the button, but only by manually dragging the character to the top. This leads me to believe it may be a bug in the tracker itself. I know you can unshift and push items that are already in initiative, that's what my EOT script does. It just seems to not want to accept new items into the string. I'll have some time tomorrow to tinker with it, but the actual string looks like this: "[{\"id\":\"-Izz0OfkV6ontNfrFEIG\",\"pr\":2}]" so I'll try manually parsing it in, and see if that resolves the issue. edit: When I started logging Campaign.get("initiativepage") when the errors start, instead of returning true/false, it returns "7F73B956-71C3-4C5B-8C72-576EE4F15EA4"... Not positive what that means, possibly an error code, but while logging the parsed/unparsed versions of the string, it converts correctly, so that's not the issue. The problem definately exists somewhere in the state of the window, not in how the JSON string is created. double edit: after googling "7F73B956-71C3-4C5B-8C72-576EE4F15EA4", I found that it's a pageid... The problem is that I'm not logging any pageids....
The weird part is, until they added the Selected Token update, this feature worked fine. I wonder if it is related somehow.
When they released that update, they also released an update to the way the turn order is sorted (numerically, as well as for playing cards). I've tinkered quite a bit with the Select tokens for another script I'm working on, and haven't experienced any type of bug, but as for scripts involving turn order, I've seen how it tends to pop up an "Unexpected Identifier" error that only persists when used with other scripts. Not sure exactly what it is, but I'm not going to lose sleep over it, as API is still in alpha. 
I'll take a look and see if I can track this down.
Thanks bro!