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

creating API to list all player character names and stats for later use

hello all i am new to creating API's but not new with programming, but i cant seem to find any good examples on how to find and list all player characters stats to use in the same API if anyone actually has any good examples of this in use i would forever be thankful
1650690379
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
You probably need to be a little more specific. Listing all the attributes of a character can be done with a macro, and doesn't require an API. What do you want to do with the information?
well id like to able to show all player character stats from the 5e dnd sheet to log things like initiative or select specific tokens based on name or id to do things like group initiative or specific group saves... hopefully that makes sense, yes i am aware that other API's have done something similar but i am trying to learn how to do it myself instead of using others code.
1650695149
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Gotcha. The way I learned was to find a simple script that did something close to what I wanted and try to find out the way it worked, tweaking little bits. How familiar are you with JavaScript? If you are fairly familiar with it already, the Wiki has great resources , particularly the reference section in the sidebar of the linked page. If you want a from-the-beginning intro, you might find Nick Olivo's tutorial videos useful. This playlist is a good start point.
josh w. said: well id like to able to show all player character stats from the 5e dnd sheet to log things like initiative or select specific tokens based on name or id to do things like group initiative or specific group saves... hopefully that makes sense, yes i am aware that other API's have done something similar but i am trying to learn how to do it myself instead of using others code. Group initiative and groupcheck are good examples then.  But why reinvent the wheel.  Use those?
1650724476
timmaugh
Forum Champion
API Scripter
I might suggest a way to store the set of stats you'd like to pull into your report... so that your API can work across systems, and so the user can have some flexibility in what their report includes. The idea would be: 1) Give the users some place/way to designate the stats to use (the easier, more graphical, the better, but a command line will suffice). 2) Build that list into an array 3) Get the characters into an array   let playerChars = findObjs({type: 'character'}).filter(c => ...); 4) Map/Reduce the characters array using the stat array in a forEach One other thing to think about would be who will run the script, and what access they should have. So your filter on the findObjs() (which returns an array) should include some check of the message-sender having access to the character and/or being GM ( playerIsGM() ). As people have said, there are plenty of script examples to look at in the repo... or post specific questions to this forum. Lots of people willing to help!
timmaugh said: I might suggest a way to store the set of stats you'd like to pull into your report... so that your API can work across systems, and so the user can have some flexibility in what their report includes. The idea would be: 1) Give the users some place/way to designate the stats to use (the easier, more graphical, the better, but a command line will suffice). 2) Build that list into an array 3) Get the characters into an array   let playerChars = findObjs({type: 'character'}).filter(c => ...); 4) Map/Reduce the characters array using the stat array in a forEach One other thing to think about would be who will run the script, and what access they should have. So your filter on the findObjs() (which returns an array) should include some check of the message-sender having access to the character and/or being GM ( playerIsGM() ). As people have said, there are plenty of script examples to look at in the repo... or post specific questions to this forum. Lots of people willing to help! this was a huge help thank you giving me a starting point in a way that makes sense!!!
1650893050
Loren the GM
Pro
Marketplace Creator
josh w. said: yes i am aware that other API's have done something similar but i am trying to learn how to do it myself instead of using others code. If reverse engineering helps you at all to learn how someone else is pulling info, I'd suggest looking at the GMSheet script:&nbsp; <a href="https://github.com/Roll20/roll20-api-scripts/tree/master/GMSheet" rel="nofollow">https://github.com/Roll20/roll20-api-scripts/tree/master/GMSheet</a> Sorry if that isn't helpful, but as Keith said before all the scripting I know has come from learning from other completed code.