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

Blood splatter is not showing up between correct points

I've made an API script that should shower blood around in a circle based on the number on token status markers.  While it works - the blood always originates at the lower right corner of the token and goes to the right.  Not the effect I'm looking for.  So for some reason my two points aren't working...this is probably a javascript weirdness.  any help would be appreciated.  Here's the relevant portion of the script - NOTE: The points show up in the Chat correctly. for  ( k  =  0  ;  k  <  totalBleed  ;  k ++)             {                  var   x1  =  Math . round ( tok . get ( 'left' ) +  tok . get ( 'width' )/ 2 ) ;                  var   y1  =  Math . round ( tok . get ( 'top' ) +  tok . get ( 'height' )/ 2  );                  var   radius  =  140 ;                  var   angle  = (( 360  /  totalBleed ) *  k ) *  3.14159  /  180 ;                  var   p1  = {                      x :   x1 ,                      y :   y1                 };                  var   p2  = {                      x :   Math . round ( x1  +  radius  *  Math . cos ( angle )) ,                      y :   Math . round ( y1  +  radius  *  Math . sin ( angle ))                  };                  sendChat ( "Bleed: "  ,  "x1,y1:"  +  p1 . x . toString () +  ","  +  p1 . y . toString () +  " - x2,y2: "  + p2 . x . toString () +  ","  +  p2 . y . toString () ) ;                  setTimeout (()  =>  {  spawnFxBetweenPoints ( p1 , p2 , 'splatter-blood' ,  tok . get ( '_pageid' )); },  k  *  1000 );                              }
1604024527
Pat
Pro
API Scripter
Offhand? Maybe scoping? As the same vars are being re-used so - maybe it's re-using the same variables and all of the run-throughs execute and by the time all of the settimeouts hit, they all have the same numbers? Maybe try with a scoped "let" on each instead of "var?" 
Brilliant!  Definitely a javascript weirdness.  Just changing var to let made it work exactly as I want !