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 .
×

Mathematical Sequence

Hello, I would like to use sheetworker in order to make my xp_max function respond to this mathematical sequence :  where x is the lvl. When you are lvl 1, you need 100 xp to lvl up  when your are lvl 2 you 200 more, so in total its 300 etc... The problem is that even when I try to follow the examples, and everything I don't manage to set the value of a attr using the sheetworker, I'm very far from the programming field so I may just doing stupid mistake. Can you help me set up this one ? If I can provide any further information for you to help solve this little problem, please let me know !
1664565899
GiGs
Pro
Sheet Author
API Scripter
Isnt this a continuation of this thread: <a href="https://app.roll20.net/forum/post/11117578/mathematical-sequence" rel="nofollow">https://app.roll20.net/forum/post/11117578/mathematical-sequence</a> ? What sheet worker code have you tried so far (in text not a screenshot)? Are you trying to have xp_max show the maximum xp for whatever level you choose?
1664566332

Edited 1664577567
GiGs
Pro
Sheet Author
API Scripter
If I understand what you're asking, this should do it. It assumes that level is always a positive integer. &nbsp;&nbsp;&nbsp;&nbsp; on ( 'change:level' , () =&gt; { &nbsp; &nbsp; &nbsp; &nbsp; getAttrs ([ 'level' ], v =&gt; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const level = + v . level || 0 ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const triangle = level * ( level + 1 ) / 2 ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const xp_max = triangle * 100 ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setAttrs ({ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xp_max &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp;});
Sorry I haven't be very reactive I had unexpected stuff to do, I'll try this out
Hey, Sorry again, I manage to find more time today on('change:lvl', () =&gt; { getAttrs(['lvl'], v =&gt; { const lvl = +v.lvl || 0; const triangle = lvl * (lvl + 1) /2; const experience_max = triangle * 100; setAttrs({ experience_max }); }); }); I changed it to this cause my level variable is @{lvl} and xp variables are @{experience} and @{exeperience_max} Nevertherless, it doesn't seem to work&nbsp;