Page 1 of 1
I guess the Script system changed
Posted: 09 Aug 2022 23:47
by rjbill
Is there a manual for it anywhere yet?
Most of my scripts don't work now.
This script gives an error saying it needs a ')', but I have no idea where.
Maybe I'm missing it, or something has changed.
Code: Select all
Document.BeginUpdate();
var sText = Document.SelText;
if (sText == "") {
Document.SelectAll;
sText = Document.SelText;
}
for (var ii = 0; ii < sText.length; ii++;) { // starting at 1 to skip first unused
var sChar = sText[ii];
if (sChar >= '0' && sChar <= '9') {
nChar = parseInt (sChar) + 1;
if (nChar > 9) nChar = 0;
sText = sText.slice (0, ii) + nChar.toString() + sText.slice (ii+1);
}
} // for
Document.SelText = sText;
Document.EndUpdate();
Re: I guess the Script system changed
Posted: 10 Aug 2022 06:34
by pjj
When you click on the [ok] button on the modal window letting you know about the error, your caret will be placed on the offending line exactly in the place where script engine expected closing bracket -- but encountered a semicolon.
Caution, bumpy road ahead -- when you delete the semicolon, another error will pop up...
Nb. you can't use random JavaScript functions in your scripts, so instead of
parseInt you need to use
StrToInt as per
FastScript manual (PDF).
Re: I guess the Script system changed
Posted: 10 Aug 2022 11:41
by rjbill
Thanks.
It didn't move the cursor anywhere.
Strange that you can't use built-in JavaScript functions.
I changed what probably needed to be changed and now it's not giving any error messages,
but is also not doing anything.
I also added
ShowMessage("Start");
at the top of the script and that never happens, so I suppose the script is never being executed.
Code: Select all
#language JScript
Document.BeginUpdate();
var sText = Document.SelText;
var sResult = "";
var sChar = "";
var nChar = 0;
var iLength = 0;
var ii = 0;
if (sText == "") {
Document.SelectAll();
sText = Document.SelText;
}
iLength = Length (sText);
for (ii = 0; ii < iLength; ii++) { // starting at 1 to skip first unused
sChar = sText[ii];
if (sChar >= "0" && sChar <= "9") {
nChar = StrToInt (sChar) + 1;
if (nChar > 9) nChar = 0;
sChar = IntToStr (nChar);
}
sResult = sResult + sChar;
} // for
Document.SelText = sResult;
Document.EndUpdate();
Re: I guess the Script system changed
Posted: 11 Aug 2022 08:59
by pjj
rjbill wrote: ↑10 Aug 2022 11:41
Strange that you can't use built-in JavaScript functions.
It's FastScript, not JavaScript. FastScript uses its own set of functions.
Remove this line and things should get better in no time:
Use // for line comments and /* */ for block comments.
If
sChar is a string, how can you compare it with integers?
Code: Select all
var sChar = "";
if (sChar >= "0" && sChar <= "9") {
Besides in this line
Code: Select all
for (ii = 0; ii < iLength; ii++) { // starting at 1 to skip first unused
ii should start with 1 (again, this is FastScript and its quirks).
Lastly, if you want to check if a char is a digit, you can use e.g.
Code: Select all
if ((ord(str[i]) < 48) || (ord(str[i]) > 57)) {
Re: I guess the Script system changed
Posted: 11 Aug 2022 09:51
by rjbill
Thanks.
I originally didn't have the
#language JScript
but saw in the manual that it could be done, so I added it.
When I took it out, it showed the start message I added.
But then it locked the editor up and it acted strange.
This
if (sChar >= "0" && sChar <= "9") {
is comparing strings to quoted strings, not strings to integers, which I would assume is okay.
I made the changes you suggested and now it is giving me an error message of
")" expected, but I don't know to what it is referring.
Is there no way to tell us what line the error was found on? (or show the text of the line)
pjj said it puts the caret cursor on the line where the error occurs, but it's not doing that for me.
Re: I guess the Script system changed
Posted: 11 Aug 2022 10:06
by rjbill
I finally got it to run, thanks.