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] Find Token

1531675114

Edited 1531764014
MyRoll20Stuffs
API Scripter
I ' m having issues with this being able to recreate "Possible Infinite Loop Detected" reliably by using the command several times. Until I can figure out why I'm leaving this post striked out. -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- With the help of The Aaron (Thanks man!) I have a new copy of the script which should do the trick: -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- I have a few dungeons that are multiple floors and really big (100 x 100 for the larger floors) While adjusting encounters and adding / removing NPCs I sometimes forget where a token is and have a hard time finding them. Here is a quick and dirty script I wrote where you supply the token's name and it will "ping" its location and move your window centered on the token (if it finds one) Syntax: !find-token -- [token name] Here is the UPDATED Script: /* findTokenn v0.8.2 By: Kastion Profile: <a href="https://app.roll20.net/users/3173313/kastion" rel="nofollow">https://app.roll20.net/users/3173313/kastion</a> */ on('ready',()=&gt;{ const getPageForPlayer = (playerid) =&gt; { let player = getObj('player',playerid); if(playerIsGM(playerid)){ return player.get('lastpage'); } let psp = Campaign().get('playerspecificpages'); if(psp[playerid]){ return psp[playerid]; } return Campaign.get('playerpageid'); }; on('chat:message',(msg)=&gt;{ if('api' !== msg.type || !playerIsGM(msg.playerid)) { return; } const cmdName = "!find-token"; const msgTxt = msg.content; if (msgTxt.indexOf(cmdName) === 0 &amp;&amp; msgTxt.indexOf("--") !== -1 ) { let token_name = msg.content.split("--")[1]; if (token_name) { const playerPageID = getPageForPlayer(msg.playerid); const tokens = findObjs({ _pageid: playerPageID, _type: "graphic", _name: token_name.trim() }); if(tokens.length){ const doPings = () =&gt; { let t = tokens.shift(); sendPing(t.get("left"), t.get("top"), playerPageID, msg.playerid, true); if(tokens.length){ setTimeout(doPings,0); } }; doPings(); } else { sendChat('FindToken',`/w gm No tokens found on your current page named &lt;code&gt;${token_name}&lt;/code&gt;.`); } } else { sendChat('FindToken',`/w gm Please use the format &lt;code&gt;!find-token -- token name&lt;/code&gt;.`); } } }); log("-=&gt; Find Token Loaded (!find-token) [Last Edited July 15th 2018] &lt;=-"); }); Short and simple. Maybe someone will find it as useful as I have.
1531677069
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
I was just thinking about how useful something like this would be, especially if it could also return a list of all tokens on a map that represent characters. Good luck!
I got the script fixed and no more crashing. Check the above post for details and the updated script. keithcurtis said: I was just thinking about how useful something like this would be, especially if it could also return a list of all tokens on a map that represent characters. Good luck! As far as searching for all tokens that represent a specific sheet that is something for another script. I'll take a crack at it in a bit if I have time.
Just when I think I've nipped it in the bud it continues to bug out **sigh** back to work on this one I guess.
1531682408

Edited 1531682479
The Aaron
Pro
API Scripter
I sent you a PM. When you get a&nbsp; Possible Infinite Loop Detected &nbsp;error, I've found the best way to address it is by introducing the concept of a work queue.&nbsp; Javascript makes that pretty easy.&nbsp; As an example, you can take something like: const bunchOfTokens = getTokens(); bunchOfTokens.each( (t) =&gt; doThingWithToken(t) ); and change it to something like: const bunchOfTokens = getTokens(); const deferTokenWork = () =&gt; { if(bunchOfTokens.length){ doThingWithToken(bunchOfTokens.shift()); setTimeout(deferTokenWork,0); } }; deferTokenWork(); This will iterate over the bunchOfTokens array and call the function on each one, just like the first code.&nbsp; However, using setTimeout(...,0) will allow the thread of execution to pop back out of your code and perform system actions (like updating the heartbeat) between each execution of the doThingWithToken() function.
Thanks again The Aaron for the help with this. The first post has been updated with the new script.