Nasa, the script language for masochists

Everything in connection with developing aircraft for FlightGear
User avatar
jwocky
Site Admin
Posts: 1833
Joined: Sat Sep 12, 2015 12:04 pm
Contact:

Nasa, the script language for masochists

Postby jwocky » Sat Sep 03, 2016 1:28 pm

Okay, Nasal is giving me a headache again. I am in a Nasal class ...

Code: Select all

var AutopilotApplication = {

   timerAPDialog: 0,

   btnWinglevel: nil,
   btnRollhold: nil,
   btnHeadingBug: nil,
   btnTrueHeading: nil,
   btnNav1Course: nil,

   btnSpeedKIAS: nil,
   btnSpeedMach: nil,
   btnThrottle: nil,
   btnPitch: nil,

   btnVerticalSpeed: nil,
   btnPitchHold: nil,
   btnAoAHold: nil,
   btnAltHold: nil,
   txtAltHold: nil,
   btnAGLHold: nil,
   ...


You can see I defined txtAltHold
later in a method called "init"
comes

Code: Select all

      txtAltHold = canvas.gui.widgets.LineEdit.new(me.root, canvas.style, {})
         .setText("0")
         .setFixedSize(50, 25);
      me.hboxAltitude = canvas.HBoxLayout.new();
      me.hboxAltitude.addItem(txtAltHold);
      me.hboxAltitude5.addItem(me.hboxAltitude);


it obviously works because when I bring the dialog up, the field shows. Now, here begins the drama. I can't find any event type, I can listen to for a lineEdit-widget. So I have to poll it. I set me a timer and ...

Code: Select all

   update: func() {
print("update apdialog");
      setprop("/autopilot/settings/standby-altitude-ft", txtAltHold.getText());
      if (me.timerAPDialog==1) {
         settimer(me.update, 1);
      }
   }


I get the printed message, then boom ... Nasal runtime error: undefined symbol: txtAltHold
at /home/peter/flightgear/fgdevelopment/Aircraft/JPack/Voodoomaster/Dialogs/autopilot9_1.nas, line 1002

I tried also instead me.txtAltHold ... then it says "me" is undefined.
any idea what's wrong? Help is appreciated, I am total rusty after months of absence.
Free speech can never be achieved by dictatorial measures!

Octal450
Posts: 2185
Joined: Sun Oct 18, 2015 2:47 am

Re: Nasal, the script language for masochists

Postby Octal450 » Sat Sep 03, 2016 5:42 pm

come on Mumble :)

I'd be happy to help if I can

KL-666
Posts: 1610
Joined: Mon Sep 28, 2015 8:42 am

Re: Nasa, the script language for masochists

Postby KL-666 » Sun Sep 04, 2016 12:38 pm

I see a scope issue here. I do not know nasal, but generally it works like this: Variables scoped at class level can be reached via "me" in methods of that class.

What is see here is:

- in init the variable assigned is local to the method (no me used)
- i do not know where that function "update" is, but if it is a method in that class, you should definitely use me
- if it is outside the class, you need to instantiate the class and use the handle to it in the way you use me

Kind regards, Vincent

Octal450
Posts: 2185
Joined: Sun Oct 18, 2015 2:47 am

Re: Nasa, the script language for masochists

Postby Octal450 » Sun Sep 04, 2016 1:41 pm

Well if's undefined, try to see where that is defined. If it is defined above all classes, then it should work everywhere. If it's defined inside a specific class, then it won't work in all classes.

User avatar
jwocky
Site Admin
Posts: 1833
Joined: Sat Sep 12, 2015 12:04 pm
Contact:

Re: Nasa, the script language for masochists

Postby jwocky » Sun Sep 04, 2016 6:47 pm

Yeah, it is defined in THE SAME class as the method that throws the erroe. And while I usually don't need an explicit me if I am in the same class, I tried that too. Same error. So I can't access it with me nor without, I can though access it in init where I instantiated it with and without me.
Free speech can never be achieved by dictatorial measures!

KL-666
Posts: 1610
Joined: Mon Sep 28, 2015 8:42 am

Re: Nasa, the script language for masochists

Postby KL-666 » Sun Sep 04, 2016 9:03 pm

I would go for consistently using me in methods for class level variables and try to get it to work. That is to rule out any scope issues.

I also see update calling update recursively. Check if it does not get in a endless loop. It is one of the most common causes of "boom".

Kind regards, Vincent

User avatar
jwocky
Site Admin
Posts: 1833
Joined: Sat Sep 12, 2015 12:04 pm
Contact:

Re: Nasa, the script language for masochists

Postby jwocky » Mon Sep 05, 2016 4:40 pm

It doesn't go in an endless loop. it just resets the event that calls it for the next call. And no it can't go in an endless loop at this time because it still crashes
And I used consequently me only the Nasal interpreter didn't like that either. Since Nasal isn't maintained since some years anymore, we don't know what strange things lurk there and it looks more and more as if I found one. Here is the thing ...

if I define a pointer variable ...

myPointer: nil,

on class level and then doe the new in a method, it seems to establish a copy of it on method level, like a local pointer variable. Not sure why, I still hope, I only messed somewhere up.
Free speech can never be achieved by dictatorial measures!


Return to “Aircraft Development”

Who is online

Users browsing this forum: No registered users and 52 guests