I guess the Script system changed

Ask questions about how to create a script or swap scripts with other users.
Post Reply
User avatar
rjbill
Posts: 872
Joined: 13 Jun 2011 06:36

I guess the Script system changed

Post 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();
RJTE version 16.12 (actual) - 64-bit
Win 10 Pro 64-bit 8 GB RAM Intel Core i7-6700 3.40 GHz SCSI Hard Drive 1 TB

Note: The signature is dynamic, not static,
so it may not show the correct version above
that was in use at the time of the post.
User avatar
pjj
Posts: 2108
Joined: 13 Oct 2009 13:48
Location: Kraków, Poland

Re: I guess the Script system changed

Post 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).
Alium tibi quaere fratrem; hic, quem tuum putas, meus est. Titus Flāvius Caesar Vespasiānus Augustus
User avatar
rjbill
Posts: 872
Joined: 13 Jun 2011 06:36

Re: I guess the Script system changed

Post 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();
RJTE version 16.12 (actual) - 64-bit
Win 10 Pro 64-bit 8 GB RAM Intel Core i7-6700 3.40 GHz SCSI Hard Drive 1 TB

Note: The signature is dynamic, not static,
so it may not show the correct version above
that was in use at the time of the post.
User avatar
pjj
Posts: 2108
Joined: 13 Oct 2009 13:48
Location: Kraków, Poland

Re: I guess the Script system changed

Post 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:

Code: Select all

#language JScript
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)) {
Alium tibi quaere fratrem; hic, quem tuum putas, meus est. Titus Flāvius Caesar Vespasiānus Augustus
User avatar
rjbill
Posts: 872
Joined: 13 Jun 2011 06:36

Re: I guess the Script system changed

Post 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.
RJTE version 16.12 (actual) - 64-bit
Win 10 Pro 64-bit 8 GB RAM Intel Core i7-6700 3.40 GHz SCSI Hard Drive 1 TB

Note: The signature is dynamic, not static,
so it may not show the correct version above
that was in use at the time of the post.
User avatar
rjbill
Posts: 872
Joined: 13 Jun 2011 06:36

Re: I guess the Script system changed

Post by rjbill »

I finally got it to run, thanks.
RJTE version 16.12 (actual) - 64-bit
Win 10 Pro 64-bit 8 GB RAM Intel Core i7-6700 3.40 GHz SCSI Hard Drive 1 TB

Note: The signature is dynamic, not static,
so it may not show the correct version above
that was in use at the time of the post.
Post Reply