javascript replace function

1533937130
So I want to replace all instances within a file of the special character expanded BACK to the special character. In this case I need to replace the string & with just &, simple right? Well the api script editor WILL NOT save the command properly, because it interprets & as & which is silly. So when I enter this: StatBlock = StatBlock.replace(/&/g, "&"); and I hit save and refresh and look at the script again the result is this: StatBlock = StatBlock.replace(/&/g, "&"); which is NOT correct.  The & is a literal pattern and SHOULD NOT be interpreted.
1533939874
The Aaron
Pro
API Scripter
Try: /[&]amp;/g
1533941849

Edited 1533941885
Well at least the script editor took that.  But it didnt work.  It didnt replace the ' string in the file with '   StatBlock = StatBlock.replace(/[&]apos;/g, "'");
1533945796
Scott C.
Pro
Sheet Author
API Scripter
Where is this "file" coming from? Are you getting the text of a gmnotes/bio/notes section of a character/handout/token, the text of an attribute, or is this a chat message?
1533966134

Edited 1533966214
Yes, the 4e drop file is in the gm notes section of the token. It is a 4e generated file - character builder The conversion script is one Sky authored a long time ago but I asked and Sky no longer supports it.  So I am modifying the broken parts of the code myself.
1534090952
Ok, so I am making some progress, but really this setup is driving me crazy. 1. I used Sky's script by adding it in the script editor and it shows up as a tab for me now there.  Yay. 2. I modified the script of course to fix the problems.  No change I write is ever effective in any way. 3.  Of course I reload Roll20 assuming the load of the environment is needed for the new script.  No change. 4. I literally delete the script entirely and ... no change.  That's right.  The script still works without it being in the tabs.  WTH? 5. I also tested the sendchat function adding direct feedback into the script to track if that code was being executed and it never output in the chat.  So beyond adding the script the first time, it appears I cannot effect it anymore.  What is going on?
1534126677
Why would that happen?  
1534127520

Edited 1534127536
If you are not already doing so, I suggest you open the API script editing window in one browser/window and the game in another so you can quickly go back and forth between the two, and monitor the API console window for errors/messages. You can also restart the API sandbox with the Save Script button on that page. For most API scripts, I have found you do not need to reload the tabletop. Some scripts require the player ribbon to be on the active page/map to take effect. Be sure that is the case for your testing.
1534134055
All of these things are true.  I wasn't sure when the reload happened.  It is good news that the save button causes it.  Still, I cleared the script and saved and it still worked.  I DO NOT UNDERSTAND how that makes any sense.
1534134638
Whatever this is was not true yesterday and quite suddenly is true today. Your scripts are currently disabled due to an error that was detected. Please make appropriate changes to your scripts and click the "Save Script" button and we'll attempt to start running them again.  More info... For reference, the error message generated was:  Error: Firebase.set failed: First argument contains undefined in property 'current' Error: Firebase.set failed: First argument contains undefined in property 'current' at Ba (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:9:49) at Ba (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:10:207) at Aa (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:8:462) at J.set (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:146:98) at createObj (/home/node/d20-api-server/api.js:2703:26) at AddPCAttribute (apiscript.js:408:18) at apiscript.js:238:2 at eval (eval at <anonymous> (/home/node/d20-api-server/api.js:151:1), <anonymous>:65:16) at Object.publish (eval at <anonymous> (/home/node/d20-api-server/api.js:151:1), <anonymous>:70:8) at /home/node/d20-api-server/api.js:1634:12
1534134686

Edited 1534135163
I have no idea what this means.  Firebase?  ... They ask me to fix the error and it is not in the script I have.  I return the favor. Looks like restart fixed that thing ... on we go ... Nope, it's back.  And now I cannot get that script to work at all.  So I restart the sandbox, its fine.  I run that script now, and i get that firebase error above and nothing works.  Before it at least worked part way, making the journal entry and a lot of the powers.  Now, nothing.
1534173312

Edited 1534173373
Seriously, the API engine has worked itself into a corner.   What do I do?  I tried sequencing the name of the function as I thought maybe it had some internal remnant of the old name. But that did not work.
1534176026
The Aaron
Pro
API Scripter
Firebase is the system that Roll20 uses to synchronize information between the clients (players) and servers for a Game.  What the above means is that somewhere in your API scripts, an invalid value has been written into an Attribute, which Firebase is unable to synchronize, causing the API Sandbox to crash. In all likelihood, the issue is that the New Text Editor inserts HTML elements which the API script is not prepared to deal with.  This causes it's parsing of the GM Notes text to go awry, resulting in bad values being written into the Attribute objects it is dealing with, crashing the API in the manner described above.  I'm having this problem with some of my scripts as well. The fix for this is not so simple.  Ideally, the New Text Editor will get adjusted to only insert HTML if the user starts inserting HTML elements (like headers and bold text, etc).  Realistically, all existing scripts that read any of the long-form text fields (gmnotes, bio, notes, etc) will need to deal with the new reality that "invisible" HTML elements will be injected into the code.  I haven't had the chance to look at this yet, but it's possible a single function could be written which would sanitize the text back to the format it was in before the New Text Editor came into existence.
1534176029

Edited 1534176146
Scott C.
Pro
Sheet Author
API Scripter
Ok, gonna try to work through all the posts since I last checked the thread. series0 said: All of these things are true.  I wasn't sure when the reload happened.  It is good news that the save button causes it.  Still, I cleared the script and saved and it still worked.  I DO NOT UNDERSTAND how that makes any sense. This isn't possible. I would guess that you had two versions of the script installed (which would also explain why changes you were making weren't taking effect). Do you have a screencap of your api page? series0 said: Whatever this is was not true yesterday and quite suddenly is true today. Your scripts are currently disabled due to an error that was detected. Please make appropriate changes to your scripts and click the "Save Script" button and we'll attempt to start running them again.  More info... For reference, the error message generated was:  Error: Firebase.set failed: First argument contains undefined in property 'current' Error: Firebase.set failed: First argument contains undefined in property 'current' at Ba (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:9:49) at Ba (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:10:207) at Aa (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:8:462) at J.set (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:146:98) at createObj (/home/node/d20-api-server/api.js:2703:26) at AddPCAttribute (apiscript.js:408:18) at apiscript.js:238:2 at eval (eval at <anonymous> (/home/node/d20-api-server/api.js:151:1), <anonymous>:65:16) at Object.publish (eval at <anonymous> (/home/node/d20-api-server/api.js:151:1), <anonymous>:70:8) at /home/node/d20-api-server/api.js:1634:12 This means that you are trying to set an attribute to an invalid value (specifically to "undefined"). It is happening at a createObj call in a function named AddPCAttribute. Ninja'd by Aaron
1534177710
OK, I do understand.  Thanks for your replies. @Aaron, I am assuming that the New Text Editor is a bit of code used in parsing the scripts for the API engine.  So it sounds like what I am doing has no chance of fixing the issue.  It sounds like the changes must be made on your end.  Was this change (the New Text Editor) something that happened in the last few days?  Because literally like a few days ago I started this effort mostly.  I loaded the script ... and ... it worked.  It created a journal entry and named all the powers.  That was the first issue with the apostrophes in the power names.  I couldn't get the script editor to deal properly with the replace function, so, I just batch file pre edited the input file, ... no trouble. On to the next. So, I noticed that the script was not changing the 4e sheet values for the statistics of the character.  I thought, wow that would be like test #1 of such a script.  I checked the code and sure enough there was not (to me) a clear place where the statistics themselves were being transferred.  I began to write that code emulating and using the existing loop structures.   It was odd that some values were transferred to the 4e sheet properly and the ones I named, and I do know the sheet from the Wiki page, so I know the sheet's internal names, did not work.  I could not understand how some worked and some did not.   But here's the thing, the code kept working just fine, otherwise, as in it continued to create a journal entry and not just fail. I added some chat messaging to test intermediate values and that part of code was certain to execute and ... no message.  I was like, WTH! So then I saw the script engine message.  I restarted the api using that button, and, NEVER RECOVERED. That button caused the script to never work again. I had originally named the script IMPCHAR for import character.  I thought, well, symbol collision, somehow.  So, I thought, delete that sucker and re-paste, re-create it.  I did that.  Named it ImportCharGenFile.  Same issue.  Then I renamed the internal function name.  Instead of build_character, build1_character, same theory.  Same issue.
1534177819
I tried to insert image here and the url is grayed out and the upload just spins.  Neither works. Here is a link: Image
1534177869
So, of course the question becomes,. what do I do?  When and is the New Text Editor going to be changed?
1534179695

Edited 1534180394
Geh!
1534179951
Null protected the AddPCAttribute call and it works again, base.  On I go ...
1534186015
The Aaron
Pro
API Scripter
The New Text Editor is Roll20's thing, not mine.  However, I might be able to make a general purpose function to contribute to the API Community to use. The reason some of them work has to do with the history of Character Sheets.  If this is the Script I'm thinking of, it likely predates the existence of Character Sheets on Roll20.  Character Sheets are really just a pretty interface around Attributes and (conceptually) Abilities.  When the script you use runs, it creates Attributes, some of which line up with the Character Sheet.  Probably at one point the Character Sheet mapped exactly to the Script's Attributes, but over time they have diverged.  
1534195684

Edited 1534195852
I agree.  I am working through that now. 
1534290310
I suppose it's too much to ask for the script editor to have basic human decency and indicate the line number of the problem causing the lock in the script.
1534292369
The Aaron
Pro
API Scripter
If it is the only enabled script, it will have the right line number. 
1534292768

Edited 1534292874
There is only 1 script and there is no line number. It says things like unexpected token and illegal value ... and ... no line number where that occurred. Of course I can usually figure it out, but sometimes i do add like a cut and paste large block of code and then ... ugh ... where is it.
1534296309
The Aaron
Pro
API Scripter
https://closure-compiler.appspot.com/home  Does a great job of finding those things. 
1534378896
Cool ty!