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
This post has been closed. You can still view previous posts, but you can't post any new replies.

} in a string litteral getting interpreted/replaced whenever api is loaded/saved. This might not be a bug but it is weird behavior to be on the lookout for.

1456129397

Edited 1456286747
Chris D.
Pro
Sheet Author
API Scripter
Compendium Curator
I found an amusing little behavior in the API. In fact I can't actually write this up perfectly, because all the & #124; codes in my examples keep getting interpreted. Suffice it to say that the first code example should be showing & #125 (without the extra space) as a code, not the pipe character; I am writing code that is writing a drop down query macro, and changing the macro button as conditions change.  I want this macro to have submenu's, so of course it has to replace all the closing brackets, pipes and commas with the appropriate code, like this. (without spaces between the & and the #).  var sm = ":" + submenu.replace( /\}/g, "& #124").replace( /\|/g, "& #125").replace( /\,/g, "& #44"); Now the funny thing is that it all worked and was tested and all OK yesterday, but today it was not working.  Then I noticed that in my code, } and the other two codesvhad been interpreted so the line looked like var sm = ":" + submenu.replace( /\}/g, "}").replace( /\|/g, "|").replace( /\,/g, ","); IE: it now says replace all the pipes with pipes, not replace all the pipes with the code for pipes.  So I put it back how it needed to be, and it was fine until I saved it and then exited and reentered the scripts environment, by which time they had been interpreted again! So the work around was to break the code up into two pieces. var sm = ":" + submenu.replace( /\}/g, "&"+"#125;").replace( /\|/g, "&"+"#124;").replace( /\,/g, "&"+"#44;"); Like I said, this might not be a bug per see, but it is something to watch out for, and if you need the actual codes in your code, break them up into two parts. 
1456254238
Phil B.
Forum Champion
Sheet Author
Hey Chris, thanks for pointing this out with the workaround and everything. This is probably a side-effect of sorts from the code editor and is not something that we can easily fix. It also doesn't seem like it would effect many people, and if it does they can use the workaround you suggested, so it's probably not worth the amount of effort it would take to "fix" it. I hope it's not too much of an issue for you.
1456287095
Chris D.
Pro
Sheet Author
API Scripter
Compendium Curator
No issue at all. It was obvious what was going on once I actually noticed it, and I can see how/why it is doing it and that changing it would be almost impossible. I just wanted to have the behaviior docuented so that anybody searching the forum could find it. 
1456339224
Phil B.
Forum Champion
Sheet Author
Alright, thanks Chris for pointing this out and I'm sure anyone looking up this weirdness will also appreciate the documentation. Since we appear to be done here, I'm going to go ahead and close the ticket.