Board index FlightGear Development Nasal

loading *.nas file and undefined symbol...  Topic is solved

Nasal is the scripting language of FlightGear.

loading *.nas file and undefined symbol...

Postby Kugelfang » Sun Apr 24, 2022 2:44 pm

I'm sure this is a face-palm moment but I'm just not seeing it.

I'm assigning some keys to rotate some model parts. I need to clamp the rotation between 265 and -265. (I saw a clamp function but let's leave that be for now.)

In my -set.xml I have the following code to limit the rotation. The first key (f/102) works fine. But the second key (F/70) would need a '<' which messes up the xml parsing. Rather than have messy, repetitive xml with CDATAs thrown about, I'd like to create a separate *.nas file with a generic function.

Code: Select all
...

   <!--Turret Rotation -->
   <key n="102"> <!-- 102=f  70=F 114=r 82=R-->
      <name>f</name>
      <desc>Rotate forward turret to port</desc>
      <repeatable type="bool">true</repeatable>
      <binding>
        <command>nasal</command>
        <script>
          var prop = "/sim/model/fore-turret-bearing-deg";
          var value = getprop(prop);
          value = value == nil? 0 : value + 1;
          value = value > 265 ? 265 : value;
          setprop(prop, value);
        </script>
      </binding>
   </key>

   <key n="70"> <!-- 102=f  70=F 114=r 82=R-->
      <name>F</name>
      <desc>Rotate forward turret to starboard</desc>
      <repeatable type="bool">true</repeatable>
      <binding>
        <command>nasal</command>
        <script>
          turrets.rotate_turret("/sim/model/fore-turret-bearing-deg");
        </script>
      </binding>   
   </key>

...

  <nasal>
    <turrets>
      <file>Aircraft/USS_Olympia/Nasal/turrets.nas</file>
    </turrets>
  </nasal>

</PropertyList>



Here's the contents of turrets.nas:

Code: Select all
#functions for handling the turrets

print("Loaded turrets.nas");

var rotate_turret = func(prop) {
  var value = getprop(prop);
  value = value == nil? 0 : value - 1;
  value = value < -265 ? -265 : value;
  setprop(prop, value);
};


In sim, this results in "Nasal runtime error: undefined symbol: turrets"

Which makes me think that either FG isn't reading in turrets.nas or it's a name space issue. I don't think the <turrets> tags are strictly necessary. Wouldn't just including turrets.nas create a 'turrets' name space? In any case, I get the same results with and without the <turrets> tag. If I leave the turrets. out of the function call I get an undefined symbol error on 'rotate_turret'.

The file path is: '/home/jeff/FlightGear/Aircraft/USS_Olympia/Nasal/turrets.nas'.

What blindingly obvious thing am I missing?

TIA

--jeff
We were set in our ways. We believed in a good God, a bad Devil and a hot Hell, and more than anything else we believed that the same good God did not intend man should ever fly.
--Bill Tate (Crouch, The Bishop's Boys)
Kugelfang
 
Posts: 178
Joined: Sun Dec 24, 2006 1:40 pm
Location: Silver Spring, MD, USA
Version: 2020.4.0
OS: Linux Mint 20.3

Re: loading *.nas file and undefined symbol...

Postby TheEagle » Sun Apr 24, 2022 5:24 pm

Please add the XML parts which load the Nasal file and the keyboard binding using the function from the Nasal file ! I hope you didn't suppose all files inside myAircraft/Nasal get automagically loaded by FG ? ;)
Cessna 210 (Wiki)
My other aircraft: my wiki profile !
Other: FGTools (GitHub)
World tour: View on SkyVector
Please consider donating $1 / €1 to help me finance a new camera !
User avatar
TheEagle
 
Posts: 3411
Joined: Sat May 01, 2021 3:27 pm
Location: France
Pronouns: You, he
Callsign: F-EAGLE
IRC name: none
Version: Git next
OS: Ubuntu Studio 22.04

Re: loading *.nas file and undefined symbol...

Postby Thorsten » Sun Apr 24, 2022 5:37 pm

Which makes me think that either FG isn't reading in turrets.nas or it's a name space issue. I don't think the <turrets> tags are strictly necessary. Wouldn't just including turrets.nas create a 'turrets' name space?


Surely this is standard debugging 1x1. First make sure that the Nasal file is actually loaded by making sure it prints a log message upon loading, if that is not the case determine what keeps it from loading.

Once it is loaded, use the Nasal console to manually run a test function from it. If that is not the case, check for typos somewhere.

Finally, check the key binding code, see if you can call a different Nasal function from the key binding, best work from working examples changing one bit a time.

Usually that get you to the bottom of things - at least it's more promising than hoping that someone might spot the thing that is off by reading code snippets...
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: loading *.nas file and undefined symbol...

Postby Kugelfang » Sun Apr 24, 2022 9:56 pm

... determine what keeps it from loading.


Well, that's the question!

It's not loading. In fact, it appears the only place it can load from is /fgdata/Nasal. Once loaded, the script/function works fine.

I've tried loading it from various directories without success. I don't see any directory permission issues and other files certainly get used by FGFS out of the same directories (granted, with <path> rather than <file>).

Is there some specific sequence when nasal files need to be loaded? Maybe it's being loaded too late? I've got the <nasal><file> at the end of the -set.xml file.

I'd like to keep the script in the 'local' nasal directory since it's pretty specific to this 'aircraft'.

I'll have to poke around and see if any of the downloaded planes I have are loading their local nasal files.
We were set in our ways. We believed in a good God, a bad Devil and a hot Hell, and more than anything else we believed that the same good God did not intend man should ever fly.
--Bill Tate (Crouch, The Bishop's Boys)
Kugelfang
 
Posts: 178
Joined: Sun Dec 24, 2006 1:40 pm
Location: Silver Spring, MD, USA
Version: 2020.4.0
OS: Linux Mint 20.3

Re: loading *.nas file and undefined symbol...

Postby TheEagle » Sun Apr 24, 2022 10:00 pm

I need the <nasal> section from your -set.xml file … (and while you mentioned it - for loading Nasal files you DO use <file>, not <path> !)
Cessna 210 (Wiki)
My other aircraft: my wiki profile !
Other: FGTools (GitHub)
World tour: View on SkyVector
Please consider donating $1 / €1 to help me finance a new camera !
User avatar
TheEagle
 
Posts: 3411
Joined: Sat May 01, 2021 3:27 pm
Location: France
Pronouns: You, he
Callsign: F-EAGLE
IRC name: none
Version: Git next
OS: Ubuntu Studio 22.04

Re: loading *.nas file and undefined symbol...

Postby Kugelfang » Sun Apr 24, 2022 10:11 pm

It's in my first post. Scroll to the end of the first code section.
We were set in our ways. We believed in a good God, a bad Devil and a hot Hell, and more than anything else we believed that the same good God did not intend man should ever fly.
--Bill Tate (Crouch, The Bishop's Boys)
Kugelfang
 
Posts: 178
Joined: Sun Dec 24, 2006 1:40 pm
Location: Silver Spring, MD, USA
Version: 2020.4.0
OS: Linux Mint 20.3

Re: loading *.nas file and undefined symbol...

Postby TheEagle » Sun Apr 24, 2022 10:41 pm

Oh, sorry, I don't know how I overlooked that … :oops:
Okay, do you ever get the "Loaded turrets.nas" print in the Nasal console ? Do you get any Nasal errors (apart from that turrets is not defined) ?
Cessna 210 (Wiki)
My other aircraft: my wiki profile !
Other: FGTools (GitHub)
World tour: View on SkyVector
Please consider donating $1 / €1 to help me finance a new camera !
User avatar
TheEagle
 
Posts: 3411
Joined: Sat May 01, 2021 3:27 pm
Location: France
Pronouns: You, he
Callsign: F-EAGLE
IRC name: none
Version: Git next
OS: Ubuntu Studio 22.04

Re: loading *.nas file and undefined symbol...

Postby Thorsten » Mon Apr 25, 2022 7:10 am

It's not loading. In fact, it appears the only place it can load from is /fgdata/Nasal. Once loaded, the script/function works fine.


Well, xml being xml, a likely scenario is that the <nasal> tag isn't where you think it is but one level too deep in the hierarchy - then it won't be loaded.
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: loading *.nas file and undefined symbol...  

Postby Kugelfang » Mon Apr 25, 2022 7:38 pm

Found it. I haven't seen it documented (but I've not read much regarding Nasal yet, either) but it appears you can only have one set of <nasal></nasal> at the top level in the -set.xml file. There was already a <nasal> section earlier in the file containing Anders' water and walker stuff. I had added a second set of <nasal> tags just before the closing </PropertyList> tag. Once I removed my <nasal> tags and moved the <file> tags to within the first <nasal> section it worked as expected.
We were set in our ways. We believed in a good God, a bad Devil and a hot Hell, and more than anything else we believed that the same good God did not intend man should ever fly.
--Bill Tate (Crouch, The Bishop's Boys)
Kugelfang
 
Posts: 178
Joined: Sun Dec 24, 2006 1:40 pm
Location: Silver Spring, MD, USA
Version: 2020.4.0
OS: Linux Mint 20.3

Re: loading *.nas file and undefined symbol...

Postby TheEagle » Mon Apr 25, 2022 8:04 pm

Yes you can only have one <nasal> section in every -set.xml file. Or, no, that's not right - you actually can have several, which creates nasal[0]/, nasal[1], … nodes in the property tree, but only the first <nasal> section nasal[0] will actually be used by FlightGear, whereas inside the <nasal> section you can have as many subnodes as you want, each with as many <file> paths as you want - every subnode of the <nasal> section will create a Nasal namespace and all <file>s of the subnode will be loaded into that namespace.
Cessna 210 (Wiki)
My other aircraft: my wiki profile !
Other: FGTools (GitHub)
World tour: View on SkyVector
Please consider donating $1 / €1 to help me finance a new camera !
User avatar
TheEagle
 
Posts: 3411
Joined: Sat May 01, 2021 3:27 pm
Location: France
Pronouns: You, he
Callsign: F-EAGLE
IRC name: none
Version: Git next
OS: Ubuntu Studio 22.04

Re: loading *.nas file and undefined symbol...

Postby cgdae » Mon Apr 25, 2022 8:20 pm

I wonder how difficult it would be to show a warning if FG finds a nasal[n] section where n is not zero.

And are there any other places where whole sections of XML can get silently ignored like this?

- Jules
cgdae
 
Posts: 117
Joined: Tue May 31, 2016 8:35 pm

Re: loading *.nas file and undefined symbol...

Postby TheEagle » Mon Apr 25, 2022 8:32 pm

It should be as simple as adding following code into $FGDATA/globals.nas:
Code: Select all
if (size(props.globals.getChildren("nasal")) > 1) {
    message = "Multiple <nasal> sections in the aircraft's -set.xml file detected - all but the first will be ignored !";
    logprint(LOG_ALERT, message);
    gui.popupTip(message);
}


And yes, you can put ANY amount of ANY nodes into FG XML files - anything that FG doesn't need will be silently ignored (there are a few exceptions though, such as the generic systems and instrumentation files).
Cessna 210 (Wiki)
My other aircraft: my wiki profile !
Other: FGTools (GitHub)
World tour: View on SkyVector
Please consider donating $1 / €1 to help me finance a new camera !
User avatar
TheEagle
 
Posts: 3411
Joined: Sat May 01, 2021 3:27 pm
Location: France
Pronouns: You, he
Callsign: F-EAGLE
IRC name: none
Version: Git next
OS: Ubuntu Studio 22.04

Re: loading *.nas file and undefined symbol...

Postby wkitty42 » Tue Apr 26, 2022 9:49 am

it would be very nice if that error message printed the exact name of the xml file containing the defect, too...

does the wiki page on nasal mention that only one nasal section is ""allowed""?
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 9146
Joined: Fri Feb 20, 2015 4:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 20.04

Re: loading *.nas file and undefined symbol...

Postby cgdae » Tue Apr 26, 2022 10:21 am

If someone (Kugelfang?) can verify that TheEagle's patch works, i'd be happy to commit it to fgdata.

- Jules
cgdae
 
Posts: 117
Joined: Tue May 31, 2016 8:35 pm

Re: loading *.nas file and undefined symbol...

Postby Thorsten » Tue Apr 26, 2022 3:08 pm

And are there any other places where whole sections of XML can get silently ignored like this?


Plenty...

It's like everywhere else in coding, you have to be careful in what you're doing, slipping xml tags a level deeper than you think will render the AP dysfunctional, duplicating an existing node will create a new instance, failure to assign a high n to property rules will overwrite the global property rules responsible for weather interpolation and such like, effect xml works different from xml elsewhere and for instance condition tags simply don't work inside effects,...

(You might guess it, but I've done or seen all of these in the past at some point...)

I don't feel that this needs any 'fixing' though - these generally are logical errors, and we don't try to fix them via compiler warnings in C++ either.
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am


Return to Nasal

Who is online

Users browsing this forum: No registered users and 3 guests