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] Light-Crumb Trail (to let players see where they've been with dynamic lighting on)

1483081035

Edited 1483657667
plexsoup
Marketplace Creator
Sheet Author
API Scripter
Edit: I've updated the LightCrumb script on Gist (sorry it's not 1-click install yet). <a href="https://gist.github.com/plexsoup/64852540504101b52" rel="nofollow">https://gist.github.com/plexsoup/64852540504101b52</a>... (For newcomers, it's a script to leave a trail of torches behind characters, with control set to "all players". That way, they can see where they've been, even when dynamic light is turned on. No more sea of blackness.&nbsp; Video here ) It now accepts these macros: !LightCrumb (show help) !LightCrumb-status (show who's registered to leave an automatic light trail) !LightCrumb-register @{selected|token_id} (register a new token as a trail mapper) !LightCrumb @{selected|token_id} (drop a new lightcrumb) !LightCrumb-clear (remove all the lightcrumbs and clear the register so no one's authorized to leave automatic trails) Still To Do: Accept distance parameters for the automatic trails. Accept an option to limit trails to a certain number.. reuse the oldest ones. Implement better error checking on inputs. (Right now the script could break if the commands aren't exactly right.) Do some testing to check edge cases and errors. fix the problem where gm isn't always on player page add option to use dim light for torches, or a smaller radius offload math functions to VectorMath and PathMath implement light-occlusion detection (to detect dynamic light walls between current location and the last known lightcrumb) fix the help text. it's showing divs and not showing curly braces Implement 1 click installation. update !LightCrumb-register to drop a lightcrumb token right away add an option to use invisible tokens instead of dropped-torch tokens add more gui buttons, for when a token is already selected instead of target-clicking. consider an option to have the trails only visible to the player who dropped them. Then everyone would have to drop their own trails. Solves the split-party problem. would it be cool if there was an option to have them burn out over time?
1483082258

Edited 1483090513
plexsoup
Marketplace Creator
Sheet Author
API Scripter
Whoops: I just read this info about the Mark script: "Markers are cleared when the Turn Order changes, is closed, or when the player page changes." That means the light-crumb trails will disappear unless you also comment out (add // before the line) the reset() commands in the script. All but the one under case "!mark-clear".
Designate someone to "mark the path" using the drawing tool, this needs to be someone who will not mess up your maps too much. If there are intelligent beings in there with your victims , um players, they can erase sections and change markings. I would use a color that is very similar to the one the players used, but not an exact match, the smarter players will catch on...
1483170324
plexsoup
Marketplace Creator
Sheet Author
API Scripter
I've modified the script and posted it on Gist so you can copy/paste into your scripts without editing anything. <a href="https://gist.github.com/plexsoup/64852540504101b52" rel="nofollow">https://gist.github.com/plexsoup/64852540504101b52</a>... (I'm not comfortable doing 1-click installs yet. Plus, it's not my script. It's The Aaron's script with a few small modifications.) Also, I've updated the video, so you can see it on a bigger dungeon: <a href="https://youtu.be/iIZxO9NPN4g" rel="nofollow">https://youtu.be/iIZxO9NPN4g</a>
For reference, the error message generated was: ReferenceError: LightCrumbImageURL is not defined
1483297879

Edited 1483297910
plexsoup
Marketplace Creator
Sheet Author
API Scripter
Oh dang. Sorry that didn't work. And here I thought I had it all figured out. Anyone know what's wrong with LightCrumbImageURL in the script?
1483300085

Edited 1483300425
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
You're coding in strict mode which means you need to declare variables using "var" or "let".
1483309747
plexsoup
Marketplace Creator
Sheet Author
API Scripter
Awesome! Thanks Scott. I've updated the script.
1483315656
vÍnce
Pro
Sheet Author
Nice mod to torch. &nbsp;Very handy. &nbsp;This cause much lag?
1483317188

Edited 1483317206
plexsoup
Marketplace Creator
Sheet Author
API Scripter
Not sure about the lag yet. I haven't tried it in an actual live game. Seemed ok in testing. I'd probably want to keep the extra light sources down to 20 or less. Right now, someone has to click the macro button to place a lightcrumb, but I'm planning to modify the script so it automatically pops out a lightcrumb every 100' or so for the official trailmarking character.
1483317443

Edited 1483317474
Pat S.
Forum Champion
Sheet Author
Instead of a set distance of 100', why not just a set number of hex or squares or even allow the gm to set the variable. This would allow for a variable scale as I could use this in a hex crawl exploration that I'm tinkering with.
1483317553
vÍnce
Pro
Sheet Author
Very cool. &nbsp;Feature thought: &nbsp;Maybe after X amount of drops the oldest drop gets removed? &nbsp;;-)
1483317725
Pat S.
Forum Champion
Sheet Author
Vince said: Very cool. &nbsp;Feature thought: &nbsp;Maybe after X amount of drops the oldest drop gets removed? &nbsp;;-) That would be nice but I would think that should be an optional feature to be enabled. I know with what I'm working on, a crumb drop light would have to remain pretty much pemenantly.
1483319343
vÍnce
Pro
Sheet Author
Definitley an option.
I don't know if I'm running into an issue because I also have Mark API installed, but here is the error message I'm getting now: For reference, the error message generated was: TypeError: Cannot read property 'count' of undefined TypeError: Cannot read property 'count' of undefined at _.each._.each.ops.*./.+.ops.*./._.each.state.Roll20AM.playLists.(anonymous function).currentTrack._.some._.some._.each.msg.playerid.dropLightCrumb (apiscript.js:8603:28) at apiscript.js:8570:6 at Function._.each._.forEach (/home/node/d20-api-server/node_modules/underscore/underscore.js:153:9) at _.each._.each.ops.*./.+.ops.*./._.each.state.Roll20AM.playLists.(anonymous function).currentTrack._.some._.some._.each.msg.playerid.handleInput (apiscript.js:8569:7) at eval (eval at &lt;anonymous&gt; (/home/node/d20-api-server/api.js:144:34), &lt;anonymous&gt;:65:16) at Object.publish (eval at &lt;anonymous&gt; (/home/node/d20-api-server/api.js:144:34), &lt;anonymous&gt;:70:8) at /home/node/d20-api-server/api.js:1394:12 at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:560 at hc (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:39:147) at Kd (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:546)
1483357677
plexsoup
Marketplace Creator
Sheet Author
API Scripter
Hmm. That's good to know. Thanks. I'll look into it. I probably need to do better input checkung. To help me troubleshoot it, are you sending it "!LightCrumb @{selected|token_id}" or "!LightCrumb@{target|token_id}" ? &nbsp;
1483367788
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
DM Robzer said: I don't know if I'm running into an issue because I also have Mark API installed, but here is the error message I'm getting now: For reference, the error message generated was: TypeError: Cannot read property 'count' of undefined TypeError: Cannot read property 'count' of undefined at _.each._.each.ops.*./.+.ops.*./._.each.state.Roll20AM.playLists.(anonymous function).currentTrack._.some._.some._.each.msg.playerid.dropLightCrumb (apiscript.js:8603:28) at apiscript.js:8570:6 at Function._.each._.forEach (/home/node/d20-api-server/node_modules/underscore/underscore.js:153:9) at _.each._.each.ops.*./.+.ops.*./._.each.state.Roll20AM.playLists.(anonymous function).currentTrack._.some._.some._.each.msg.playerid.handleInput (apiscript.js:8569:7) at eval (eval at &lt;anonymous&gt; (/home/node/d20-api-server/api.js:144:34), &lt;anonymous&gt;:65:16) at Object.publish (eval at &lt;anonymous&gt; (/home/node/d20-api-server/api.js:144:34), &lt;anonymous&gt;:70:8) at /home/node/d20-api-server/api.js:1394:12 at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:560 at hc (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:39:147) at Kd (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:546) Hi DM Robzer. Based on that error message it looks like you might be having an issue with my Roll20AM script actually, although I'll have to refresh my memory as I don't remember a count variable in there. It is weird that it is saying it has an issue in both scripts tho.
1483381231

Edited 1483382701
!LightCrumb @{selected|token_id} I am now in the process of removing the Roll20AM and will reinstall this script and report back. &nbsp;Thanks for the prompt replies!!
I have removed Roll20AM and reinstalled the LightCrump script. &nbsp;I do have Mark installed as well during these last two attempts. &nbsp;This is the error message: TypeError: Cannot read property 'count' of undefined TypeError: Cannot read property 'count' of undefined at dropLightCrumb (apiscript.js:7475:28) at apiscript.js:7442:6 at Function._.each._.forEach (/home/node/d20-api-server/node_modules/underscore/underscore.js:153:9) at handleInput (apiscript.js:7441:7) at eval (eval at (/home/node/d20-api-server/api.js:144:34), :65:16) at Object.publish (eval at (/home/node/d20-api-server/api.js:144:34), :70:8) at /home/node/d20-api-server/api.js:1394:12 at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:560 at hc (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:39:147) at Kd (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:546)
1483381826

Edited 1483382334
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Ah, realized what the problem is (at least in LightCrumb). Plex, you need to define the lightcrumb variable in the state. Right now it's seeing "state.LightCrumb.count=0" at line 74 and/or "count=++state.LightCrumb.count;" 197, but as far as the API knows, there isn't a state.LightCrumb defined. Before this: state.LightCrumb.count=0; Or this: count=++state.LightCrumb.count; You need something like this: state.LightCrumb = state.LightCrumb || { count:0 }; I'd recommend putting a checkInstall function in that confirms things like that are created. See pretty much any of Aaron's scripts for an example of it -- I completely copied my script architecture off of him. EDIT: I'm pretty sure this was the problem, and it was saying there was an issue with Roll20AM due to some screwiness with not being able to find the LightCrumb object in the state (only a WAG though) because I've confirmed there is no variable named count in the Roll20AM script, inside state.Roll20AM or just in the code.
The macro I'm using is set up as a token action and is: &nbsp; &nbsp;!LightCrumb @{selected|token_id}
1483383442
Gold
Forum Champion
Thanks for the script development work on this. I plan to try it. Will this be coming to the one-click API repository of Roll20?
1483385969
Pat S.
Forum Champion
Sheet Author
That would be really cool if it does. Right now I don't know what type of dependencies it requires so I have not tried to install it yet.
1483388867
plexsoup
Marketplace Creator
Sheet Author
API Scripter
Thanks for your help Scott and everyone! I'd like to make it a 1-click install. But first I have to&nbsp;make the script better / more reliable. Right now it's still essentially: "Aaron's Mark script with a few extra light settings, but broken because I tinkered with things I didn't understand." Once I get it fixed, and especially when I can make it drop light-tokens automatically, then I'll start worrying about the 1-click process. (I would love to get my API scripter badge, but I feel like I don't deserve it yet.)
1483390303
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Heh, I'm still not sure why I got a badge. It just appeared one day.
I think you need to allow the script to accept parameters.&nbsp; You may not always want the light crumb to have the same pre-programmed values for light radii. For instance, on an overland hexcrawl map, you may want it to have a small radius, so as to reveal only adjacent hexes (which may be in miles or other large units).&nbsp; Then when you're indoors, you may want it to give torch-light radius or similar. I could be wrong (Javascript is not a strong suit for me), but I only see a fixed configuration in the script, which means you'd actually need 2 different scripts to do that now in the same campaign.
1483402874
plexsoup
Marketplace Creator
Sheet Author
API Scripter
Good idea Anthony! Thanks
1483404147

Edited 1483404168
plexsoup
Marketplace Creator
Sheet Author
API Scripter
I'm still trying to figure out the basic script architecture.. &nbsp;Can anyone explain the purpose of this statement at the end of the primary function? return { &nbsp; &nbsp; RegisterEventHandlers: registerEventHandlers, &nbsp; &nbsp; CheckInstall: checkInstall, &nbsp; &nbsp; Reset: reset }; And what's this thing for? (At the end of the primary function.) }()); (I get why there's a curly brace and a round bracket, but why the extra pair of brackets? ) Also: what happens when you include the logical or ( || ) in a variable assignment? &nbsp; &nbsp; state.LightCrumb = state.LightCrumb || { count:0 }; or &nbsp; &nbsp; var LightCrumb = LightCrumb || (function LightCrumbTrailMaker() { Does it try one then try the other if the first fails? Nevermind the last one: Found the answer...&nbsp; <a href="http://stackoverflow.com/questions/2100758/javascr" rel="nofollow">http://stackoverflow.com/questions/2100758/javascr</a>...
1483404907

Edited 1483405301
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
plexsoup said: return { &nbsp; &nbsp; RegisterEventHandlers: registerEventHandlers, &nbsp; &nbsp; CheckInstall: checkInstall, &nbsp; &nbsp; Reset: reset }; This is how you can call these functions from outside of the script's namespace, particularly in your on("ready",...) section at the very end. And what's this thing for? (At the end of the primary function.) }()); (I get why there's a curly brace and a round bracket, but why the extra pair of brackets? ) I'm not a great programmer knowledge wise, but I believe this is so that you can return your functions from the self-invoking function LightCrumb. I fully expect a certain Arcane Scriptomancer to hop in here and give a better explanation.
1483433290
plexsoup
Marketplace Creator
Sheet Author
API Scripter
For any other amateur coders paying attention, that little }()); dealie at the end is part of the "Javascript Module Pattern" <a href="http://stackoverflow.com/questions/17776940/javasc" rel="nofollow">http://stackoverflow.com/questions/17776940/javasc</a>... From what I can tell, it basically ensures that a script is only instantiated once (like a singleton). Then that instance of the script continues to operate and serve up requests while it's listening for events.
1483446647
plexsoup
Marketplace Creator
Sheet Author
API Scripter
Thanks for everyone's help. Big update. Automatic light trails! You still have to get it&nbsp; on the Gist Let me know if you have any problems. (It's not super well tested.)
1483453723

Edited 1483466953
Ada L.
Marketplace Creator
Sheet Author
API Scripter
Sounds like a handy script. Do you plan to publish it to the Roll20 scripts repository (and to the One-Click install library)? Also, to shorten your script a little bit, you could leverage the Vector Math script ( <a href="https://github.com/Roll20/roll20-api-scripts/tree/" rel="nofollow">https://github.com/Roll20/roll20-api-scripts/tree/</a>... to do your vector mathematics operations. It already handles adding and scaling vectors, getting the distance between points of arbitrary dimension, and more. (It is super well tested)
1483500667
plexsoup
Marketplace Creator
Sheet Author
API Scripter
@Stephen L: That sounds pretty good! I see you even have a distance function. So, forgive my ignorance... How do I include functions from another script? Also, how do I make sure people have both scripts installed?
1483504662
plexsoup
Marketplace Creator
Sheet Author
API Scripter
I updated the Gist with a bugfix. (top and left coordinates were reversed for some tokens, so reused light crumbs were dropping in the wrong place)
1483507081

Edited 1483507152
plexsoup
Marketplace Creator
Sheet Author
API Scripter
Stephen, any chance of adding an intersect (or raycast) function to your vector math library? I need to check to see if the vector defined by [currentLocation, lastLightCrumbLocation] instersects with any nearby paths on the dynamic lighting layer. If they intersect, then I know light is occluded, so I should drop a new LightCrumb.
I am no longer getting a error message when I install the script. &nbsp;However I am not seeing any functionality. &nbsp;I may be dense. &nbsp;I select a player token and enter in the command&nbsp;!LightCrumb-register selected|token_id to register the token (no visual confirmation anything happened) and then I have a token action macro with the command line&nbsp;!LightCrumb selected|token_id and I see nothing. &nbsp;Am I not using this properly?
1483529522

Edited 1483529899
plexsoup
Marketplace Creator
Sheet Author
API Scripter
Try &nbsp; &nbsp; !LightCrumb-register @{selected|token_id} With the curly braces and the at sign it works best if you make a macro and put it on the token bar you can also do: &nbsp; &nbsp;!LightCrumb @{selected|token_id} to drop a single torch &nbsp; &nbsp; !LightCrumb-clear to remove all the torches &nbsp; !LightCrumb-status to show which token_ids are registered to leave light trails
1483529991
plexsoup
Marketplace Creator
Sheet Author
API Scripter
Good point about the lack of user feedback when registering a token. I need to improve that.
If I enter&nbsp;!LightCrumb-register @{selected|token_id} into chat without a token selected, I do get an error message in chat:&nbsp; "You attempted to use a roll command looking for the value of a selected token, but no tokens are selected." If I select a token and then I enter&nbsp;!LightCrumb-register @{selected|token_id} into chat I see nothing (so I assume the token is registered properly). Then I have a token macro set up that executes&nbsp;!LightCrumb @{selected|token_id} and I see nothing different. &nbsp;I move the token and I see nothing different. &nbsp;I run the token macro again and I see nothing different. I am about three or four days into being a Pro subscriber and this is my first time working with API scripts, so I apologize if I am not using your script properly. &nbsp;But I am still confused as to how to use this script.
1483530458
plexsoup
Marketplace Creator
Sheet Author
API Scripter
No need to apologize. If it seems like it isn't working, it's my fault for making it either broken, or obtuse. try putting your !LightCrumb-register @{selected|token_id} inside a token action macro
1483530514

Edited 1483530722
I have two token actions now ... the LightCrumb Register, and the LightCrumb. &nbsp;Not seeing a difference at this point. &nbsp; Do I need to have a specific torch graphic in my art library or something?
1483530641
plexsoup
Marketplace Creator
Sheet Author
API Scripter
I don't think you need a specific torch icon. But i could be wrong about that.
1483530943

Edited 1483531014
This is the link I used to grab your script ...&nbsp; <a href="https://gist.github.com/plexsoup/64852540504101b520b25f7c3fa84e5f" rel="nofollow">https://gist.github.com/plexsoup/64852540504101b520b25f7c3fa84e5f</a> Also, I am signed in as the GM, not as a player. &nbsp;Would this explain what I'm seeing?
YEP !!! &nbsp;Sheeshhh. &nbsp;I resigned in as a player and it looks like it is working for me.
1483531565

Edited 1483531642
plexsoup
Marketplace Creator
Sheet Author
API Scripter
Strange. I can't explain that. It was working for me as player or gm I'll have to do more troubleshooting. Do you see the little torches appear when you move the token around?
Yes, the automatic drop is working very well now. &nbsp;Another odd observance is now that I've signed back in as the GM, it seems to be working for me as a GM now. &nbsp;That boggles my mind.
I believe it may have to do with the Player Ribbon. &nbsp;When I have the Player Ribbon on my sign in screen map page and just move to the dungeon map as the GM, LightCrumb does not work for me. &nbsp;But when I move the Player Ribbon over to the dungeon map and still operate as the GM, then the LightCrumb functions are working.
Another thought .... when the torch icon drops, it drops on top of the registered token. &nbsp;Because of this, when I go to grab the player token to move it, I am actually grabbing the torch first. &nbsp;Is it possible to have the torch drop but "to the back" on the token layer?
1483532328

Edited 1483532362
plexsoup
Marketplace Creator
Sheet Author
API Scripter
That makes sense... i didn't account for the player ribbon adequately. I still have lots to learn!
1483532403

Edited 1483532509
You are doing great! &nbsp;You are Light(crumb) years ahead of me in scripting, for sure!
1483532533
plexsoup
Marketplace Creator
Sheet Author
API Scripter
&gt;&nbsp;when the torch icon drops, it drops on top of the registered token. Weird. It was going to the back for me. i'll have to investigate that tomorrow. Thanks for testing it, and providing me with all the awesome feedback!