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

[Script Help] Starfinder by Roll20 sheet and repeating rows

Hey Folks,  I am at my wit's end here and I want to see if it's me screwing up or if the sheet hates me. Buckle up as this has some parts and may be a bit rambling.  So I've written a script to take a JSON for a Starfinder Starship and import it into the character sheet. The various systems and weapons are, of course, repeating rows. I stole The Aaron's script to make row IDs and the systems (like sensors, computers, power cores, etc) import great. However, the weapons are not showing up at all. The totally weird part is that when I use timmaugh's Xray script to examine the character, all of the attributes are there right where they should be. They even exist when I make a @{selected|repeating_attack_$X_name} call. I just cannot get them to display on the sheet though.  Is it possible there is a hidden attribute in the repeating_attack section (For the weapons) that displays them on the sheet? If so, how would I even go about finding that? I'm including the code snippets involved. Hopefully, this can help.  Create Attribute function const createAttribute = (name, current) => {   if (current == undefined) { log(`Starship Import: no value found for ${name}, skipping create.`); return;   } createObj('attribute', { name : name, current: current, characterid: character.id   }); }; Here is the relevant weapons code. All weapons are stored in an array within the JSON which is why I have the for loop.  for (i=0; i<starshipData.weapons.length; i++) {         var weaponRowID = generateRowID(); let range = starshipData.weapons[i].range.split(" ") switch (range[0]) {     case "Short": rangeNumber = 5; break;     case "Medium": rangeNumber = 10; break;     default: rangeNumber = 20; break; };     //Name     createAttribute("repeating_attack_" + weaponRowID + "_name", starshipData.weapons[i].name); //Type     createAttribute("repeating_attack_" + weaponRowID + "_type", starshipData.weapons[i].type.replace(" ","-").toLowerCase());     //Class     createAttribute("repeating_attack_" + weaponRowID + "_class",starshipData.weapons[i].class); //Range     createAttribute("repeating_attack_" + weaponRowID + "_range", rangeNumber); //DamageRoll createAttribute("repeating_attack_" + weaponRowID + "_damage_dice",starshipData.weapons[i].damage.dice.count + "d" + starshipData.weapons[i].damage.dice.sides); //Arc createAttribute("repeating_attack_" + weaponRowID + "_arc",starshipData.weapons[i].installedArc); //PCU     createAttribute("repeating_attack_" + weaponRowID + "_pcu", starshipData.weapons[i].pcu);     //Build Points     createAttribute("repeating_attack_" + weaponRowID + "_bp", starshipData.weapons[i].cost); //speed     createAttribute("repeating_attack_" + weaponRowID + "_description", starshipData.weapons[i].speed); }; A fresh pair of eyes will be greatly appreciated. I would also not rule out the possibly of a small shrine as well. 
1626997733
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Hi Erik, There isn't a hidden attribute for the display, it just displays based off of the arc attribute. However, what are you entering for the arcs?
1626998267

Edited 1626998302
Here is the first entry in the particular JSON I'm using for import.    "weapons": [     {       "id": "1850932218",       "name": "Light Plasma Cannon",       "description": "",       "class": "Light",       "type": "Direct Fire",       "range": "Short (5 hexes)",       "speed": null,       "damage": {         "dice": {           "count": 2,           "sides": 12         },         "damage": [],         "alternateDamage": null       },       "damageMultiplier": null,       "pcu": 10,       "cost": 12,       "special": null,       "installedArc": "Forward",       "linkedTo": null,       "reference": {         "name": "Core Rulebook",         "shortName": "CRB",         "page": 302       }     }, I'm using the command:  createAttribute("repeating_attack_" + weaponRowID + "_arc",starshipData.weapons[i].installedArc); So the installed arc should be set to Forward I thought. 
1626999057

Edited 1626999196
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Ah, ok, I see the problem (or at least a problem). The arc attribute expects a lowercase arc name. Additionally, in my own tests I was having difficulty getting it to properly create with just createObj. I switched to using the API version of setAttrs and it worked fine. Here's my test code that could be used as a starting point: on('ready',()=>{ let character = findObjs({name:'Freighter'})[0];//Hardcoded which ship to apply to for the test. Obviously you'd do this dynamically with your code let row = `repeating_attack_${generateRowID()}`; const setObj = {}; setObj[`${row}_name`]='API created'; setObj[`${row}_arc`]='aft'; log({setObj}); setAttrs(character.id,setObj,{silent:true}); }); EDIT: And additionally, pretty much every attribute that is a select or radio expects a lowercase value. In the case of the fire type, it expects either "direct-fire" or "indirect"
Scott,  Shifting the arc to lower case worked perfectly. All weapons popped up like a charm.  I shall begin building your personal shrine today.  Thanks!