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

Left Brackets....they task me!

Hi All, I'm trying to write out some link/action button text that starts with a "[".  However, no matter what I do, its printing as "NaN".  Huh?  No kidding is not a number, duh!.  It is driving me nuts.  Any advice would be appreciated.  Thank you! The desired output(without entities):   [@{ repeating_spell-1_-LjIvduM5HQUE-NdoYNr_spellname}](~Albido Puddifoot|repeating_spell-1_-LjIvduM5HQUE-NdoYNr_spell) Current output: NaN@{repeating_spell-1_-LjIvduM5HQUE-NdoYNr_spellname}](~Albido Puddifoot|repeating_spell-1_-LjIvduM5HQUE-NdoYNr_spell) Here's what I've tried: const ch = function ( c ) { var entities = {              '@' : '#64' ,              '{' : '#123' ,              '|' : '#124' ,              '}' : '#125' , '#' : '#13' , '[' : '#91'         };          if ( _ . has ( entities , c ) ){              return ( '&' + entities [ c ]+ ';' );         }          return '' ;     }; lvlText += ch ( '[' )+ ch ( '@' )+ ch ( '{' )+ entry + "_spellname}](~" + automateObj . charactername + "|" + entry + "_spell) " ;
1563653249
GiGs
Pro
Sheet Author
API Scripter
Try isolating this bit ch('[')+ch('@')+ch('{')+entry+"_spellname}](~"+automateObj.charactername+"|"+entry+"_spell) and lvltext and see what they show. It's hard to know exactly what's going on here without knowing what lvlText is. You can also try replacing  ch('[')+ with '['+ and see how it goes. You dont usually need to html replace left brackets. Finally you could try putting a space either side of the  ch('[')+ like + ' ' + ch('[')+ ' ' + I seem to remember there;s a bug with spaces (or there lack of them) that crops up in the API with macro strings on some very specific occasions related to bracket positioning, but I cant remember what they are.
Thanks for the response, GiGs!  Yeah, I was stumped on why the left bracket was causing issues too.  And yeah, I've tried to just go with it as a literal left bracket.  I didn't think about seeing whats being concatenated into the "lvltext" string prior to this.  Its possible that's causing issues.  
1563655118
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
So, what it looks like to me is that you've got lvlText being set to NaN at some point first. I'd also recommend using the template literal format for concatenating; it'll make the code easier to read: lvlText += `${ch('[')}${ch('@')}${ch('{')}${entry}_spellname}](~${automateObj.charactername}|${entry}_spell)`; I also want to wonder why you're escaping [@{ . The only way I can think of that would need this is if you are nesting the button inside a roll query, although I'd think that a chat menu to call the various other chat menus would be better.