You're welcome, just passing on what the community has taught me. You can actually make this a lot easier to add additional menu types to. var abilObj = findObjs({ _type: "ability", _characterid: char.id, }); actionButtons = "<br><table><tr><td colspan=\"2\"><b>Actions:</b></td></tr>"; _.each(abilObj, function(obj) { if (obj.get("name").indexOf("Attack-") !== -1) {//This will be true if attack shows up anywhere in the name. That may be what you want, but just wanted to point it out. Also, if you really want to go with using an if statement, I'd use the javascript function startsWith instead of indexOf macroName = obj.get("name"); actionName = obj.get("name").substr(7).replace("-", " ");//using .substr makes this so that it will only work with attack at the start (or another 6 letter word), but if you want say spells you'll need to copy the code with a different subStr in it. actionButtons += '<td>['+actionName+'](~@{'+charName+'}|'+macroName+')</td>'; }; }); What I'd recommend: var abilObj = findObjs({
_type: "ability",
_characterid: char.id,
});
actionButtons = "<br><table><tr><td colspan=\"2\"><b>Actions:</b></td></tr>";
//Assume that you have some sort of command handler that processes a chat message like !menu --Attack to then send a menu of the selected character's attacks
//Assume that this handler passes the menu type into this function via a variable named menuType
_.each(abilObj, function(obj) {
obj.get('name').replace(new RegExp('^'+menuType+'-(.*)','i'),(macroName,actionName)=>{//The regex will test the name of the obj and only proceed to the function if there's a match
actionButtons += '<td>['+actionName+'](~@{'+charName+'}|'+macroName+')</td>';
});
});