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

API script idea - Sum columns in a text field

1516822994
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
I don't know if such a thing exists, but I can see a good use for it. Is there a script which can extract the numerical value from each line of a text field and return a total? The use case I envision is using the notes (or other unused field) of a character sheet to record XP. The field could be filled with: 200 Fought some Orcs 350 liberated the Gnome King 1000 Lair of the Wyrmlings The script could reference that field and return "1050", which could either be entered manually into the XP field, or transferred with something like ChatSetAttr. Other uses could be Simple monetary bookkeeping. Simply add a positive or negative value and note to a line. Update a money field by the methods above. Long term tracking of the passage of days. Anyway, I've come to the conclusion that the API is beyond my abilities at this point, but I'm throwing the idea out to any of our scripters who might also see the value of the idea.
1516827144
The Aaron
Pro
API Scripter
It can be done.  The actually extraction of the number and summation is pretty easy.  As with most API scripts, it's really a question of the interface.
1516835284
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
I think I see what you mean. The number would need to go someplace other than the chat window? I.e. be returned in a usable format? "!total --notes_field" might return 1050 to chat, but you couldn't "grab" that number to throw into another field with chatsetattr? It seems like it would need to duplicate the functionality of chatsetattr by putting the number into a field that could be later referenced by other scripts or macros?
TheAaron's script will probably not return 1050.... His script would give the right answer: 1550 :-)
Rabulias said: TheAaron's script will probably not return 1050.... His script would give the right answer: 1550 :-) I was wondering if I should comment that Keith obviously needs a script to do math for him.  But your comment is sufficient I think.  ;)
1516848488
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Ha! I shall go do the dance of shame. And my wife is a math teacher. For penance, I shall not edit.
1516850626
Gold
Forum Champion
I get what you're asking for, I really do, and I like the idea fairly well. I might use it for XP. I keep XP already in that format. Here is how I currently list XP (on the Bio tab), following your example but adding the part I add: 200 Fought some Orcs 350 liberated the Gnome King 1000 Lair of the Wyrmlings TOTAL: /r 200+350+1000 Just keeping a running list of the numbers with /r already typed in front of it. Easy to copy-paste that math into Chat and get the result total at any time.
1516856258
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
That's a pretty clever idea. Works for me.
1516864121
vÍnce
Pro
Sheet Author
/r 200+350+1000 lol.  Never would have crossed my mind to use a roll to do that Gold.  Cool.  
You can have an attribute, let's say XP List,  that you add each item to it as you go, and in your example, end up with: 200 [Fought some Orcs]+350 [liberated the Gnome King]+1000 [Lair of the Wyrmlings] [[@{XP list} ]] will give you 1550, and you can mouse over it to see what it represents. Set a token to an XP sheet and you can click/add to the running total, using the API.
1517190710
GiGs
Pro
Sheet Author
API Scripter
That's actually pretty clever
1517190951
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
That has the advantage of automation, but at the cost of readability. It's a cool solution, though.
1517194761
GiGs
Pro
Sheet Author
API Scripter
If you use a textarea on the character sheet, it can be spacious and pretty readable, and you can print @{XP List} without the double square brackets to get a very printable report in chat. So something like Experience: @{XP list} Total: [[@{XP list} ]] Would look pretty reasonable.
1517208887
Gold
Forum Champion
Vince said: /r 200+350+1000 lol.  Never would have crossed my mind to use a roll to do that Gold.  Cool.   It's pretty funny the first few times. Fellow players will remark on the high-figure roll, since we're used to seeing so many lower totals from d20's, d6, and d100. But yeah, the Roll20 Roller and also Google's search box, can do basic math like a calculator with +, -, * for multiplication, and / for division.
1517238978
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Yeah, I think I will likely go with Gold's option. I can write an Applescript to parse out the numbers and format the list. I like the readability of the output.