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

Triggering changes based on changes to values tied to Token's Radial Menu Bubbles

When we play, I tie attr_current_llife_points to one of my token's radial menu bubbles.  I wrote the code below to update related values based on changes to attr_current_llife_points, through the radial menu bubbles.  However, it's not getting called.  My code is below.  Is this not something you can do? // update life points by change in current // TODO when I have a function to calculate maximum_life_points, move this logic into "set physical strength fields" function, as I've done with action points and agility on('change:current_life_points', () => { getAttrs(['current_life_points', 'maximum_life_points', 'fatal_life_points_clean'], values => { const max_life_pnts = int(values.maximum_life_points); const ftl_life_pnt = int(values.fatal_life_points_clean); var crnt_life_pnts = int(values.current_life_points); const spnt_life_pnts = max_life_pnts - crnt_life_pnts; if (crnt_life_pnts <= ftl_life_pnt) crnt_life_pnts = "Dead (" + crnt_life_pnts + ")"; console.log('current_life_points: ' + crnt_life_pnts); setAttrs({current_life_points: crnt_life_pnts}); }); });
1589512257
GiGs
Pro
Sheet Author
API Scripter
First thing to check since I cant see the rest of you code: do you have the int function in your code? But the bigger issue is here: on('change:current_life_points', () => { setAttrs({current_life_points: crnt_life_pnts}); You have created an infinite loop here. When current life points changes, it triggers setAttrs, which changes current life points, which triggers setAttrs, etc. You hsould add {silent: true} to setAttrs, so this worker doesnt trigger itself. setAttrs({current_life_points: crnt_life_pnts}, {silent:true}); Another issue is you are using current_life_points as a number, but also storing text in it (the word Dead and brackets). if (crnt_life_pnts <= ftl_life_pnt) crnt_life_pnts = "Dead (" + crnt_life_pnts + ")"; Yes, parseInt will extract a number from text, but its really not a good idea. You should have one life points value that is always and only a number, and have a second attribute that is just for display purposes where you show any status with the number.
Well that was all good advice.  I really should have taken another pass at that before I posted it.  I should have known that stuff.  Thanks for your help.  It's all working now.
1589678189
GiGs
Pro
Sheet Author
API Scripter
Good to hear :)