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] Teleport group of tokens to specified page.

1417322475

Edited 1417368768
This is my first published script effort, so please be kind ;) There are several teleport scripts that I've seen that teleport tokens to a location on the same page. I could not, however, find a script to teleport the tokens to a completely different page. This one does just that. The command syntax is: !pageport name:&lt;page name&gt; You must have at least one token selected for this to work. It will teleport up to 24 tokens. On the destination page, you must have a token called "LandingPad" and all the tokens will be placed arrayed around it. The script is here: <a href="https://gist.github.com/BardMorgan/858ba8673fb5c28" rel="nofollow">https://gist.github.com/BardMorgan/858ba8673fb5c28</a>... UnicornIsle is simply the namespace I'm using for all my scripts, to avoid confusion and collision with scripts with similar names. The HandleChat function is what I use to handle my API functions that are triggered by a chat command. It calls the ParseArgs function, which parses the string of arguments. My functions use the &lt;name&gt;:&lt;value&gt; format, separated by commas. ParseArgs splits those out into a javascript object and returns the object, which may then be passed to another function. The DuplicateToken function takes a source token, pageId, and coords object and duplicates the source token on the specified page, at the specified coordinates (top, left). The Teleport function checks to see if any tokens are selected, and if not, sends an error message via chat. If tokens are selected, it tries to find the destination page, and if it does not exist, sends an error message via chat. It then checks for the existence of a token with the name "LandingPad" on the destination page. If no token is found, it sends an error message via chat, otherwise, it then iterates through the selected collection, calling TeleportCharacter for each one, and incrementing the index variable to put each token at a new position around the landing pad. Since the API does not have (at this time) a way to delete the old tokens on the original page, I simply move them to the gm layer for deletion later. I also could not find a way to move a single character to the new page, so that is left as a manual process. The TeleportCharacter function calculates the coordinates of the new token based on the position and the landing pad token's location. The variable unitPixels is set to 70 (the default number of pixels per unit). I've tested this and it should work, but as always, let me know if you find something that doesn't, or if you can suggest an improvement.
1417324038
The Aaron
Roll20 Production Team
API Scripter
Looks pretty good. One problem people may run into is the API can only set imgsrc to something in a player library, so if they have a token that uses a marketplace image, it will likely be created with no image or fail outright. I like the way you aren't polluting the global scope with your variables. Good for you! =D Unimportant but you might be interested in knowing that you could replace this: on("chat:message", function(msg) { UnicornIsle.HandleChat(msg); }); with this: on("chat:message", UnicornIsle.HandleChat); Though you might need to move it to the bottom so that UnicornIsle.HandleChat has been defined first. Welcome to the scripting! =D
1417326693
The Aaron
Roll20 Production Team
API Scripter
I could be wrong, but it looks like landingPad is never defined.
1417360047

Edited 1417360080
Aaron, you are correct. I did some last minute editing to move the definition of landingpad out of the TeleportCharacter function. That avoids it having to be pulled for each and every character. Instead, I moved it up to the Teleport function, so it's only defined once and then passed on multiple times. More efficient. Unfortunately, those edits didn't make it completely into the Gist. I've updated the Gist, and it should be correct now. Thanks for catching that!
Ok, is there something I have to do to update the gist preview? It still has the wrong version. I've tried clearing my cache, re-editing the post, and removing and re-adding the preview link.
Oh, as far as the function definition goes, yeah, I normally do that, but I had a log(msg) in there to see the message at one point and removed it without redoing the code.
1417364507
The Aaron
Roll20 Production Team
API Scripter
BardMorgan said: Ok, is there something I have to do to update the gist preview? It still has the wrong version. I've tried clearing my cache, re-editing the post, and removing and re-adding the preview link. The forum caches based on the url. I thwart the caching by appending a hash fragment with the version number of my script (and I have a version number). ...some_url/foo#v0.2
Thanks! That worked.
Script works, but only some tokens get transported.
I'm using it in my game right now and have seen the same thing. I'll try to figure it out.
1417403010
The Aaron
Roll20 Production Team
API Scripter
Any errors in the API console?
It's VERY intermittent. I can do the teleport 20 times in a row, then it fails twice... Couldn't get the error message during my game, but I'll keep trying.