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

[Help] Import API Repeating Sections

1453528510

Edited 1453529723
Corin S.
Sheet Author
Hello code wizards! I'd appreciate any guidance here. So here's the scoop. I've been maintaining  this PTU sheet for a while now, and the main complaint has simply been that most people use an automated Google Drive sheet already, and updating two character sheets is a pain. So, I had the idea to make a bit o' API code, so at least Pro users could save on some hassle. The basic idea is that, if I can create a copyable string serving as a JSON file in the original sheet, I could have the API put it into a R20 sheet. Here's what I have so far: charImport = function(imp,play) {     var char = JSON.parse(imp);     var x = createObj("character", {         name: char.nickname,         inplayerjournals: play,         controlledby: play     });     for (var property in char) {     if (char.hasOwnProperty(property)) {         createObj("attribute",{             name:property,             current:char[property],             characterid:x.id         });     } } }; charUpdate = function(imp,play,name) {     var char = JSON.parse(imp);     if(!name){         var name = char.nickname;     }     var list = filterObjs(function(obj) {         if (obj.get("_type")=="character"&&obj.get("name")==name&&(obj.get("controlledby")=="all"||obj.get("controlledby").indexOf(play)!=-1)) {return true;}         else {return false;}     });     var report = findObjs({_id: play})[0];     if(list.length == 0){         sendChat("Importer", "/w ".concat(report.get("_displayname").concat(" There's no character by that name. Try charImport instead.")));     } else if (list.length > 1){         sendChat("Importer", "/w ".concat(report.get("_displayname").concat(" There's more than one character by that name. I'm not sure which one should be edited.")));     } else {     var sheet = list[0];     sheet.set({name: name});     var attrs = findObjs({         _type:"attribute",          _characterid:sheet.id         });     var names = [];     for (var i = 0; i < attrs.length; i++) {         names.push(attrs[i].get("name"));     }     for (var property in char) {     if (char.hasOwnProperty(property)) {         if (names.indexOf(property)==-1){         createObj("attribute",{             name:property,             current:char[property],             characterid:sheet.id});}         else {             var pos = names.indexOf(property);             attrs[pos].set({current:char[property]});         }              }} }} on("chat:message", function(msg) {   //This allows players to enter !sr <number> to roll a number of d6 dice with a target of 4.   if(msg.type == "api" && msg.content.indexOf("!newchar ") !== -1) {     var imported = msg.content.replace("!newchar ", "");     charImport(imported,msg.playerid);   } else if(msg.type == "api" && msg.content.indexOf("!updatechar ") !== -1) {     var imported = msg.content.replace("!updatechar ", "");     charUpdate(imported,msg.playerid);   } }); Now, for the problem at hand: repeating sections. I'm not sure how to add new repeating sections or edit existing ones without foreknowledge of ids. Any ideas how I could build a JSON to incorporate them into this code?
1454950631
The Aaron
Pro
API Scripter
Based on this post of yours: &nbsp; <a href="https://app.roll20.net/forum/permalink/2935377/" rel="nofollow">https://app.roll20.net/forum/permalink/2935377/</a> I'm guessing you don't need help with this anymore?