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

using walls to add tree trunks to dynamic lighting in a forest map

1687874654

Edited 1687874672
I'm trying to write a macro that will auto add tree trunks to the DL layer for each of the tree tokens in a forest map. I've pretty easily made the script for adding a single trunk by making an svg file with just a circle in the centre where the diameter of the circle to size of file matches (approximately) the ratio of trunk diameter to tree crown diameter, then just using walls api while i have a tree selected to draw the circle to the DL layer. I tried using !forselected to then have this applied to each tree in a selected group but it doesn't work. Any help or alternate solutions would be much appreciated, here's the scripts i have so far: Walls macro called "add-trunk-DL": !walls begin !walls viewbox 400 400 !walls strokecolor #00ff00 !walls fillcolor transparent !walls strokewidth 5 !walls moveto 200.00 175.00 !walls curveto 233.45 175.00 233.36 225.00 200.00 225.00 !walls curveto 166.64 225.00 166.55 175.00 200.00 175.00 !walls lineto 200.00 175.00 !walls end then forselected macro (where -J- is my macro storing character): !forselected %{-J-|add-trunk-DL} I kind of expected the second macro not to work but am hoping it shows what i was trying to do and that someone on here has an idea of what i can do to make this happen. Thanks
1687890040
timmaugh
Pro
API Scripter
Hey, lark... you're pretty close. You're going to need to make 3 small changes, though. Explanation (Feel free to skip) 1. When you use a sheet-call (like retrieving an ability from your -J- character), that will expand immediately, and will add the associated verbiage (and line-breaks) to your command. That will happen before the message is handed to the scripts, so by the time forselected sees the message, the command line is actually *several* command lines... and it will only get the first. For that reason you'll want to defer the resolution of the ability retrieval by using forselected's deferral syntax. !forselected(^) You can actually pick any character, it just has to be a character that ONLY appears where you want it to be removed when forselected dispatches the outbound message... like this: %^{-J-|add-trunk-DL} 2. Also, when forselected dispatches the outbound message, it waits to receive the returned message object from Roll20 (which will have no selected token, since it was a message sent from a mod script), and it gives to that message object the next selected token in the queue. In the case of a multi-line outbound message, forselected will only be able to do that to the first line -- subsequent lines will spawn new messages to which forselected will have no visibility. To get around that, you'll want to make sure you have ZeroFrame installed, too, and then you can use ZeroFrame's batching construction to turn all of those separate commands into a single message. (ZeroFrame will dispatch them independently, but IT will then handle handing off the token it received from forselected as the selected token of each independent message.) 3. One peculiarity of the Walls script is that it collects information over several command lines to build the wall. If we start sending lines for wall 2 while wall 1 is still building/collecting, we'll run into a problem. So to get around that, we're going to use a ZeroFrame {&delay} tag in the forselected line to make sure one set of wall instructions have a chance to clear before we send the next. One second should do it, but you can adjust depending on the speed of your game. The delay tag will, itself, need to be deferred so that it isn't detected until the message coming out of forselected: {^& delay 1} I know. It's weedy down in the weeds. Solution (TL;DR) Change your add-trunk-DL ability to read like this: !{{   !walls begin   !walls viewbox 400 400   !walls strokecolor #00ff00   !walls fillcolor transparent   !walls strokewidth 5   !walls moveto 200.00 175.00   !walls curveto 233.45 175.00 233.36 225.00 200.00 225.00   !walls curveto 166.64 225.00 166.55 175.00 200.00 175.00   !walls lineto 200.00 175.00   !walls end }} And change your triggering command to read like this: !forselected(^) %^{-J-|add-trunk-DL} {^&delay 1}
1687890207
The Aaron
Roll20 Production Team
API Scripter
It's great that Tim got a solution for this.&nbsp; I think I'd approach it in a different manner.&nbsp; There's a script in the 1-Click called Dynamic Light Recorder.&nbsp; You can read about it here:&nbsp; <a href="https://app.roll20.net/forum/post/2987563/slug%7D" rel="nofollow">https://app.roll20.net/forum/post/2987563/slug%7D</a> The basic idea is, you drop the graphic on the map layer, draw the DL lines on top of it, then select both and link them.&nbsp; Then any time you drop that image on the map, it will draw those lines on the DL layer for it.&nbsp; You can even move it afterwards and it will move the lines to match.&nbsp; Not sure if it supports rotation, and it definitely doesn't support the one way and movement blocking versions of DL lines, but it should work at least as well as your walls solution, but with much less effort after the initial setup.
thanks both. @timmaugh i couldn't get your solution to work, not sure why. @theAaron i had seen that API and thought about using it but i had almost 100 dif. tree images (have dif types of tree cover; normal, jungle, swamp etc.), in the end i did it and it all seems to work fine, was a pain to apply to all the images but didn't take too long. thanks again to both of you