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

Location-Based Triggers?

I'm going to look around and try and find out how to do the type of "trapped" square setup that was in the video (such that when a player moves a token onto a specific tile, it triggers event X), but if anyone has a suggestion that would be awesome!
1367357592
Alex L.
Pro
Sheet Author
This should do it: moved to its own thread <a href="https://app.roll20.net/forum/post/140526/script-trap-script-like-in-vid#post-140526" rel="nofollow">https://app.roll20.net/forum/post/140526/script-trap-script-like-in-vid#post-140526</a> edit: updated because left and top are in px. edit edit: commented and made only work on move
from what I can gather, there's no drag or drop specific methods so you'd need to so some ghetto collision detection. My initial thought is that you can check the 'change:graphic' event and then query for objects that have the same top and left as your new location. If the query comes back with a result then you've found your trap and you can handle the event as you'd like. Otherwise just return from the function and wait for the next token move.
Hrm, if your trap graphic is a drawing and isn't snapped to the grid, the top/left method won't work.
There is actually an undocumented method I used to make my script for the video, objInPath(obj, pathobj). You pass in an object (like a graphic object) and a path object, and it will tell you if the object is inside the path. The problem right now is that there's no good way to get your paths. Maybe use findObj() and filter based on the stroke of the path? Anywho, I have some ideas on how to make this much easier in the future, but for now you can use that method if you wish.
Thanks Alex -- that's exactly what I was hoping for (pending Riley's 'easier solution', anyway)
Question part 2: how to make it trigger only once? &nbsp;(i.e., multiple characters moving to the same point over the session shouldn't get the trap mechanism. &nbsp;I was assuming some sort of var defined outside of the token that's moving, but I can't seem to pull that off. EDIT: @HoneyBadger, if you swap the == for a &lt;= or &gt;=, or both, that should solve that issue. &nbsp;Also works well for triggers like in the video, where you want something to trigger once the players pass a certain point.
1367390658
Alex L.
Pro
Sheet Author
Michael C. said: Question part 2: how to make it trigger only once? &nbsp;(i.e., multiple characters moving to the same point over the session shouldn't get the trap mechanism. &nbsp;I was assuming some sort of var defined outside of the token that's moving, but I can't seem to pull that off. EDIT: @HoneyBadger, if you swap the == for a &lt;= or &gt;=, or both, that should solve that issue. &nbsp;Also works well for triggers like in the video, where you want something to trigger once the players pass a certain point. you would just add a bool to say if its been triggered or not if it has then dont trigger if it hasnt then dont. You would have something like "var triggered = false;" before "on("change:token", function() {" then you would check it when you check the location or before, and when it finaly is triggered you just say "triggered&nbsp; = true;"
So if you have multiple scripts that fire when a token moves, how does the API decide which script works in which order?
1367394118
Alex L.
Pro
Sheet Author
HoneyBadger said: So if you have multiple scripts that fire when a token moves, how does the API decide which script works in which order? no idea, Riley could you enlighten us? But for traps you would pack it all into one script.
I was thinking of scripts that block token movement if the token is not the current token at the top of the initiative order, scripts that check for traps, or scripts that can trigger a text block and such.
The scripts fire synchronously (meaning the next function won't happen until the previous function has finished) in order of first-bound to last-bound. In addition they fire in order of specific property to general event. So for example, given the following: on("change:graphic", function1); on("change:graphic", function2); on("change:graphic:left", function3); If the graphic's left property changed, they would fire function3, then function1, then function 2.&nbsp; The Scripts for your Campaign are loaded in the same order they appear on the Script Editor page from left-to-right. So you would probably want for example to load scripts that block movement first, then scripts that check for traps second.&nbsp;
1367414905
Alex L.
Pro
Sheet Author
Thanks Riley for the confirmation Would be best to just merge the on change events for more advanced users then.