Skip to content
View in the app

A better way to browse. Learn more.

The AVSIM Community

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Jscript debugging

Featured Replies

During development of a jscript script, the script may contain syntax errors (eg typos in variables etc) that prevent the script to complete. Is there some logging available that makes it easier to locate the issue or do I need to insert manual log statements to narrow down the location of the issue?

Thanks for your help. 

Holger Schmid

  • Commercial Member

Sorry, but no, AAO doesn't have any IDE features. You would have to write your own loggers or use (LOG:text)

Personally, I am always using a simple counter variable:

(L:state) = 1;

...some code...

(L:state) = 2;

....more code...

(L:state) = 3;

etc.

This variable I then monitor with AAOs variable observer dialog.

 

Also, the AaoCmd object has .info(), .log() and .error() that write to the current script logfile in \Documents\LorbyAxisAndOhs Files\Scripts
See AAO Manual, "Special AAO features for WSH • The "AaoCmd" object:"

 

But there are more professional ways. I know of an AAO tester who wrote a voice controlled ATC interface in AAO using JScript. I think that he was using NodeJS and he wrote his own loggers etc. He sometimes hangs out on the German AAO thread on the JD Discord.

Stuff like this:

    var Fso = new ActiveXObject("Scripting.FileSystemObject"); //NODEJS Comment
    if (Debug) {   
      var Log = Fso.OpenTextFile(LogFile, 2, true); //NODEJS Comment //1 read, 2 write, 8 append
      Log.WriteLine(Timestamp() + "Starting Logging"); //NODEJS Comment
      Log.Close(); //NODEJS Comment
    }

 

Edited by Lorby_SI

LORBY-SI

  • Author

Hi Lorby_SI,

thanks again for your fast and detailed help. I really appreciate it a lot. I already use AaoCmd.log as a workaround to narrow down the location potential issues. I have hoped there is a better approach available. But finding typos for e.g. variable names is really hard work with that approach.

Just out of curiocity: How does jscript be compiled or sent to the sim? Does this provide any output that could probably be of use?

Again - thanks a lot for your help. This is really great.

Holger Schmid

  • Commercial Member
2 hours ago, geholger said:

Just out of curiocity: How does jscript be compiled or sent to the sim? Does this provide any output that could probably be of use?

That is not how this works. None of the scripts are ever sent to the sim - not RPN, not JScipt, not VBScript, not Javascript. All script processing happens either inside AAO itself (RPN), in the Windows Scripting Host (JScript and VBScript) or in Chromium (Javascript). Only the pure/singular SDK variables and events are sent to/written to/read from the simulator while the scripts are being executed by AAO.

2 hours ago, geholger said:

But finding typos for e.g. variable names is really hard work with that approach.

What kind of variables? Almost all variables that are present in the sim can be selected from lists on the Script Editor dialog. To acccess the existing LVars use "Scripting->Read LVars from sim". 
The variable syntax may have to be adjusted at times (indexes, units), but there aren't a lot that you actually have to type out in full?

One strategy is to keep AAOs variable observer dialog open while writing scripts, so you can check variable names and their contents before using them in a script. Variables can be selected from the aforementioned lists there too.

Edited by Lorby_SI

LORBY-SI

  • Author
1 hour ago, Lorby_SI said:

What kind of variables? Almost all variables that are present in the sim can be selected from lists on the Script Editor dialog. To acccess the existing LVars use "Scripting->Read LVars from sim". 
The variable syntax may have to be adjusted at times (indexes, units), but there aren't a lot that you actually have to type out in full?

One strategy is to keep AAOs variable observer dialog open while writing scripts, so you can check variable names and their contents before using them in a script. Variables can be selected from the aforementioned lists there too.

I am talking about my own variables in the jscript. For example:

(WSH:jscript|AaoEntry|ASYNC)
function AaoEntry() {
  interval = (L:A320CA_INTERVAL, String)
  if (iinterval != '') { // <<< here is a typo! "iinterval" instead of "interval"
      AaoCmd.AaoCmd.log('stopping interval='+interval);
      AaoCmd.clearInterval(interval)
  }
}

In this case, spotting the type in line #4 is easy. But imagine a jscript script with much more lines. Finding these type of errors is a nightmare as the script just stops executing after line #3 and you have to add logs to narrow down where the issue is located. I hope this will explain the problem. In this example I could have used (L:A320CA_INTERVAL) instead of a variable but the same issue exists for e.g. function calls, etc. 

Holger Schmid

  • Commercial Member
8 hours ago, geholger said:

I hope this will explain the problem.

AAO can't help you with that, the app doesn't know that the script is wrong either. The Script dialog is just a text editor, it is not an IDE for JScript. After adding the necessary interaction code, It just passes your script on to the Windows Scripting Host. The WSH will execute it - or not. AAO doesn't get any feedback regarding errors. If you are struggling with the general syntax, I would recommend using an external editor. Even Notepad++ has decent code highlighting features, but you could also use a more professional IDE for Javascript/NodeJS, like VisualStudioCode (mind you, I'm not doing this myself, but I know of people who do). Then just add the (WSH: line at the top and copy/paste the code into the AAO editor.

Out of curiosity - the code that you posted above is very wrong in many ways. Do you expect this to work or was that just written for highlighting your wishes regarding an IDE?

That being said, I will try and pass on the exceptions that the Windows Script Host throws to the script processing window in the next version of AAO. I was hoping to avoid this for performance reasons, but I see that it may be useful.
On another note, when you set ASYNC, you will not get any feedback at all. Do not set this while developing a script, only at the end, when everything is working.

Edited by Lorby_SI

LORBY-SI

  • Author

Thanks for the reply - I see that there is just no support for this by WSH. 
Regarding the code: I just spotted the wrong log-command. Besides this and the typo, I am using this in my project to clear an already running interval started in another script using AaoCmd.setInterval(). 
Any other hints what’s wrong?

Holger Schmid

  • Commercial Member
17 minutes ago, geholger said:

Any other hints what’s wrong?

The syntax should be the same as Javascript

- Every variable must be declared using "var"
- Every line of code must end with a semicolon
- String comparison uses "===" and "!=="
- "interval" might be a reserved word, I wouldn't use it as a variable name.

(WSH:jscript|AaoEntry|ASYNC)
function AaoEntry() {
  var intv = (L:A320CA_INTERVAL, String);
  if (intv !== '') {
      AaoCmd.log('stopping interval='+intv);
      AaoCmd.clearInterval(intv); 
  }
}

 

 

Edited by Lorby_SI

LORBY-SI

  • Commercial Member
9 minutes ago, geholger said:

I see that there is just no support for this by WSH. 

Well, I've hacked into the exceptions thrown by WSH, and now I get at least the "unknown variable iinterface". None of the other errors though.

But this will be part of the next AAO version, not this one. If you want to try this, send an email with your proof of purchase to the support address (last page of the AAO manual).

LORBY-SI

  • Author
8 minutes ago, Lorby_SI said:

The syntax should be the same as Javascript

- Every variable must be declared using "var"
- Every line of code must end with a semicolon
- String comparison uses "===" and "!=="
- "interval" might be a reserved word, I wouldn't use it as a variable name.

(WSH:jscript|AaoEntry|ASYNC)
function AaoEntry() {
  var intv = (L:A320CA_INTERVAL, String);
  if (intv !== '') {
      AaoCmd.log('stopping interval='+intv);
      AaoCmd.clearInterval(intv); // ??? is this supposed to work?? 
  }
}

 

 

JavaScript is not very strict - same seems to be true for Jscript which was there a little earlier. 
- the “var” is not needed, same for the semicolon 
- the === and !== is a comparison that also checks for the correct type, the == and != are also possible but omitting the type check. I don’t know if the type checking works in Jscript 
- “interval” is not reserved and indeed, the AaoCmd.setInterval() seems to return a string (seems to be something like a uuid)

Great to read that there is at least a WSH exception and that this will be made available in the next version. I will provide you with my proof of purchase later this weekend so I can give it a try. 
 

Thanks again for your great support!

Holger Schmid

  • Commercial Member
13 minutes ago, geholger said:

JavaScript is not very strict - same seems to be true for Jscript

I cannot guarantee that the same applies to the kind of processing that AAO does - deviating from syntax rules may circumvent the code extensions that AAO itself wants to do. It needs to "pimp" the code before it is sent to WSH (includes, inserts and OLE processing of variables, arrays and hashmaps). You might throw off that internal process when you are not using "proper" syntax. That goes for reserved words too. Just be careful and as accurate as possible. AAO was made for speedy execution, not development. It has zero tolerance for syntax errors, it doesn't do any plausibility checks or error handling, it is case sensitive, etc. None of the usual additional safeguards are in place, to save as many CPU cycles as possible.

Edited by Lorby_SI

LORBY-SI

  • Author

Thanks. Did not know that there is some additional pre-processing by AAO prior to sending it to WSH. So yeah - then it makes sense and I will rework my scripts to not run into any problems later. 

Holger Schmid

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.