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

Floor/ceil not defined for ChatSetAttr

I'm trying to put together a (clunky) way of using CSA so that if I use smaller denominations of coins and I haven't got enough the larger denominations are used to make the difference. For example if I have -22sp the macro will automatically minus 3 gp from my total and and leave me with 8sp, if that makes sense. This is part of what I have so far: !modattr --name @{character_name} --evaluate --sp|("%sp%" < 0) ? -10*floor(%sp%/10): 0 which will add the lowest multiple of ten to get the sp back to positive. However, when I try to run this I hit an error that Floor is not defined (same with ceil). Has anyone else encountered this or am I just making an obvious mistake? Any fix or workaround, or even better method of doing the same thing would be appreciated.
You could try Math.floor and Math.ceil since those are methods actually defined in javascript. Otherwise, you could put the calculation in an inline roll that IIRC is processed and then used by ChatSetAttr.
1509396404

Edited 1509396452
Lithl
Pro
Sheet Author
API Scripter
Looks like the value for the --evaluate option is ultimately passed to the eval function. In that case, try using Math.floor  instead of floor .
Unfortunately it doesn't look like I can do inline rolls because it doesn't like %s. I've never javascripted, so to use Math.floor is it as simple as replacing floor with Math.floor? I currently have a dodgy looking/running and slow workaround but hopefully you've fixed this problem for me. :)
1509432792

Edited 1509432804
Looks like this can be done without messing around with JS; try this: !modattr {{ --name @{character_name} --gp|-[[ {ceil(@{sp} / -10), 0}kh1 ]] --sp|+[[ {ceil(@{sp} / -10), 0}kh1 * 10 ]] }}
1509470582
Lithl
Pro
Sheet Author
API Scripter
Kyle said: to use Math.floor is it as simple as replacing floor with Math.floor? Yes, exactly. I haven't tried it myself, but a skim through the ChatSetAttr source code suggests it should work.
1509473485
Jakob
Sheet Author
API Scripter
Brian said: Kyle said: to use Math.floor is it as simple as replacing floor with Math.floor? Yes, exactly. I haven't tried it myself, but a skim through the ChatSetAttr source code suggests it should work. Yes, that's how it works, --evaluate just feeds things into eval().
Thanks for all the help guys I've got it working now and I'll definitely start looking at eval() then to see what how far I can stretch the script. Silvyre said: Looks like this can be done without messing around with JS; try this: !modattr {{ --name @{character_name} --gp|-[[ {ceil(@{sp} / -10), 0}kh1 ]] --sp|+[[ {ceil(@{sp} / -10), 0}kh1 * 10 ]] }} Although this is *a lot* neater than what I have at the moment, for some reason if I try to put 3 of these (each for cp/sp, sp/gp and gp/pp) into one macro it doesn't run properly. My guess would be something to do with calling the attribute with an @ call rather than evaluate's %% but I don't know enough about this to know for sure.
1509809116

Edited 1509809717
Kyle said:  if I try to put 3 of these (each for cp/sp, sp/gp and gp/pp) into one macro it doesn't run properly. Try this: !modattr {{ --name @{character_name} --pp|[[ {ceil(@{gp} / -10), 0}kh1 * -1 ]] --gp|[[ {ceil(@{gp} / -10), 0}kh1 * 10 - {ceil(@{sp} / -10), 0}kh1 ]] --sp|[[ {ceil(@{sp} / -10), 0}kh1 * 10 - {ceil(@{cp} / -10), 0}kh1 ]] --cp|[[ {ceil(@{cp} / -10), 0}kh1 * 10 ]] }} No need to use the --eval tag here.
Silvyre said: Kyle said:  if I try to put 3 of these (each for cp/sp, sp/gp and gp/pp) into one macro it doesn't run properly. Try this: !modattr {{ --name @{character_name} --pp|[[ {ceil(@{gp} / -10), 0}kh1 * -1 ]] --gp|[[ {ceil(@{gp} / -10), 0}kh1 * 10 - {ceil(@{sp} / -10), 0}kh1 ]] --sp|[[ {ceil(@{sp} / -10), 0}kh1 * 10 - {ceil(@{cp} / -10), 0}kh1 ]] --cp|[[ {ceil(@{cp} / -10), 0}kh1 * 10 ]] }} No need to use the --eval tag here. Just tried this and it doesn't work if there is 0 of a denomination above the one you're changing. For example if a character has only 5gp and you try to 'minus' 6cp one run through of the above will 5gp, -1sp and 4cp. After another pass it gives the correct 4gp, 9sp and 4cp but that's not very helpful if I have to run it twice.
1510029346

Edited 1510029427
Kyle said: that's not very helpful if I have to run it twice. For sure. This expanded macro should only need to be used once: !modattr {{ --name @{character_name} --pp|[[ {ceil([[@{gp} - {ceil(@{sp} / -10), 0}kh1]] / -10), 0}kh1 * -1 ]] --gp|[[ {ceil([[@{gp} - {ceil(@{sp} / -10), 0}kh1]] / -10), 0}kh1 * 10 - {ceil([[@{sp} - {ceil(@{cp} / -10), 0}kh1]] / -10), 0}kh1 ]] --sp|[[ {ceil([[@{sp} - {ceil(@{cp} / -10), 0}kh1]] / -10), 0}kh1 * 10 - {ceil(@{cp} / -10), 0}kh1 ]] --cp|[[ {ceil(@{cp} / -10), 0}kh1 * 10 ]] }}