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

Need some syntax help

1551362900
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
I am trying to pull an attr from a repeating section into an API that can be turned on/off I've got part of the syntax..I think. But I need help with the rest or it may all be jacked up. getAttrByName(character.id,repeating_ranged_ $rowid_notes );
1551364275
GiGs
Pro
Sheet Author
API Scripter
How are you determining which row of the repeating section you are using?
1551365041

Edited 1551365108
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
By using this variable that is passed to the API from the roll let rowid = cmd[2]; Which comes from a hidden @{rowid} on the specific row
1551365151
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
// Attacks const rangedBuilder = (rowid, atk) => `repeating_ranged_${rowid}_${atk}`; on("chat:message", function (msg) { if (msg.type === "api" && /^!ranged/.test(msg.content)) { // Variables from sheet var who = getObj('player', msg.playerid).get('_displayname') .split(' ')[0]; let cmd = processInlinerolls(msg).split(/\s+/); var character = getObj('character', cmd[1]); // get character id let rowid = cmd[2]; // Get Row Id var name = getAttrByName(character.id, 'character_name'); var whisper = getAttrByName(character.id, 'whispermode'); var level = Number(cmd[3]); // target var rds = Number(cmd[4]); // Rounds fired var rcl = Number(cmd[5]); // Recoil var dam = String(cmd[6]); // damage var dtype = String(cmd[7]); // damage type var table = Number(cmd[8]); // Hit Location Table Roll var subtable = Number(cmd[9]); // Subtable Roll var notesOnOff = Number(cmd[10]); // Notes on/off var note = getAttrByName(character.id, `repeating_ranged_$rowid_notes`); // Variables from API var roll = Number(randomInteger(6) + randomInteger(6) + randomInteger(6)); var successmargin = Math.abs(level - roll); var failmargin = Math.abs(roll - level); var margin = Math.abs(level - roll); var critroll = Number(randomInteger(6) + randomInteger(6) + randomInteger(6)); var result; var success; var fail; var loc; var wm; var wn; var crittable; var hits; var damrolls; var notes; if (notesOnOff === 1) { notes = note; } else { notes = ""; }
1551366503

Edited 1551366622
GiGs
Pro
Sheet Author
API Scripter
It looks like the issue is missing backtick quotes and curly brackets here: getAttrByName(character.id,`repeating_ranged_ ${rowid}_notes` ); However I notice you have a function at the top of your script that makes it easy to get this right. This bit: const rangedBuilder = (rowid, atk) => `repeating_ranged_${rowid}_${atk}`; That's a function designed to let you build the repeating attribute names correctly. You call it like so: let fieldName =  rangedBuilder(rowid,'notes'); That will give you a variable that contains the properly formatted name, and can replace your getAttrByname line with getAttrByName(character.id,fieldName); You can also combine those two stepsinto a single operation like so getAttrByName(character.id,rangedBuilder(rowid,'notes')); So putting that all together, the line that's giving you issues would become: var note = getAttrByName(character.id,rangedBuilder(rowid,'notes'));
1551370479
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
Wow I should've realized that....thanks