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

Programaticaly Populating Fieldsets

I've got a custom character sheet that uses fieldsets for the skills section. I've also got an API call that iterates through the fieldset, allowing players to roll a skill check by just using !skill Bluff, and allows our DM to use !groupSkill Spot, for example, to call a private spot check from all party members. The problem I'm facing now is that if a skill is NOT in the list, it treats the character as not having access to that skill, even if the skill is usable untrained. The stock 3.5 character sheet gets around this by having a large number of skills as part of a table, and then implementing a fieldset at the bottom for expanding the list. However, for the sake of not altering any of my existing API functions, I'd rather just create a !initializeCharacter function that prepopulates everything, which would also help with NPC generation. As part of the initializeCharacter function, I wanted to programatically populate the list with a collection of predetermined skills. Any thoughts?
1420507187
Lithl
Pro
Sheet Author
API Scripter
Why not simply include an optional second parameter to your command (eg, charisma), which the script will then use to roll the skill untrained if the proper attribute isn't found? The player can then have a macro supplying the ability to use for the skill, or they can create the ability and not train it. (And if they create the macro and then later add the ability, the ability will override whatever they put in the macro.)
Doesn't really sound that bad. You're looking at something along these lines, I think. Assuming your command calls a sheet via some ID, i.e. !InitializeCharacter [sheetid], and you have a bunch of blank attributes for the fields you are populating with skill names, and those skill names match the attribute names: skillArray = ["predetermined skill 1", "predetermined skill 2", "predetermined skill 3"] on("chat:message", function(msg) { if(msg.type == "api" && msg.content.indexOf("!initializeCharacter") !== -1) { var chatArray = msg.content.split(" "); var sheetid = chatArray[chatArray.indexOf("!initializeCharacter") + 1] /*where sheetid = journal entry id*/ var attribute = findObjs({ _characterid: sheetid, _type: "attribute", }); _.each(attribute, function(obj) { for (i = 0; i < skillArray.length; i++) { if (obj.get("name") == skillArray[i]) { obj.set("current", skillArray[i]) } } }); } }); There's probably some other code you can use to get the sheetid easier, like matching it to a "character" obj.get("name") value.
1420508272

Edited 1420508531
Now that I think about it, it would be pretty easy to populate a character sheet by inputting the name of the journal entry instead of trying to go find the id. The command here would be !InitializeCharacter [name of journal entry]. So if you have a player with a character named "Oldstuff McTuggins" in the journal, !InitializeCharacter Oldstuff McTuggins would populate the character sheets's attribute values, assuming those attribute names match a list of skill names you assign in the array below: skillArray = ["predetermined skill 1", "predetermined skill 2", "predetermined skill 3"] on("chat:message", function(msg) { var sheetid; if(msg.type == "api" && msg.content.indexOf("!initializeCharacter ") !== -1) { var journalEntryName = msg.content.replace("!initializeCharacter ", ""); var character = findObjs({ name: journalEntryName, _type: "character", }); _.each(character, function(obj) { sheetid = obj.get("_id") }); var attribute = findObjs({ _characterid: sheetid, _type: "attribute", }); _.each(attribute, function(obj) { for (i = 0; i < skillArray.length; i++) { if (obj.get("name") == skillArray[i]) { obj.set("current", skillArray[i]) } } }); } }); Note: this script wont work properly if you have multiple journal entries of the same name.
@Brian - The second parameter idea seems simple, and it would probably work. Though probably what I'll do is tuck some JSON array away somewhere in the API that contains all of the skills and fails over to that if the attribute isn't found on the character sheet. I want to leave as little room to crash the API as possible. Yet somehow my players always find a way... @John - That would work for updating the records if they already exist, but I don't think that code would create new fieldset entries and populate them. The idea was to !initializeCharacter [some identifier] and have it go from an empty fieldset to a fieldset containing all of the untrained skills.