Board index FlightGear Development

Nasal namespace problem with XML nasal/load script

FlightGear is opensource, so you can be the developer. In the need for help on anything? We are here to help you.
Forum rules
Core development is discussed on the official FlightGear-Devel development mailing list.

Bugs can be reported in the bug tracker.

Nasal namespace problem with XML nasal/load script

Postby mhab » Tue Jul 05, 2016 5:06 pm

Hello

Background: I try to improve the elevators on the FG aircraft carriers because they are way too slow.
As the speed depends on a tied property (transition-time) which is hardcoded to 150 (seconds I guess) I try to implement an alternative solution using the
aircraft.door..... mechanism which allows me to speed this up to 15 sec which is a lot more realistic for todays carrier elevators.

Problem:
I define the elevators in the XML <nasal><load> part of the carrier, as seen below
Code: Select all
  <nasal>
    <load>
      print("LOAD Vinson from ", cmdarg().getPath());

      var fg_root = getprop("/sim/fg-root");
      var self = cmdarg();

      ###########
      # elevators
      var elevator1 = aircraft.door.new("/surface-positions/elevator[0]", 15);
      var elev1_node = self.getNode("surface-positions/elevator[0]/position-norm", 1);

      # loop
      var loop = func(id) {
          ...
        var elev1 = getprop("/surface-positions/elevator[0]/position-norm");
        elev1_node.setValue(elev1);
           ...

      }

    </load>
  </nasal>

and later on I want to use this in an animation within the same carrier XML file, like below ...
Code: Select all
  <animation>
    <type>pick</type>
    <object-name>Elevator-1</object-name>
    <action>
      <button>0</button>
      <repeatable>false</repeatable>
      <binding>
        <command>nasal</command>
        <script>
          elevator1.toggle();
        </script>
      </binding>
    </action>
  </animation>

When I try this I get a Nasal error on the console which says:
"Nasal runtime error: undefined symbol: elevator1"

So obviously the variable of the nasal/open script is not known in the XML binding part.

What is the solution to this namespace problem ?

Thanks
Mike-DE
mhab
 
Posts: 418
Joined: Thu Apr 18, 2013 11:59 pm
Callsign: D-MIKE
Version: 2020.3.4
OS: Win10

Re: Nasal namespace problem with XML nasal/load script

Postby Hooray » Tue Jul 05, 2016 7:23 pm

I haven't looked at the code in question or actually tried this, but you can check the caller() and closure() APIs (wiki) to determine the surrounding/outer namespace, you can then use debug.dump() (or debug.bt() ) to dump everything to the console.

As a workaround, you could access the globals hash to look up the corresponding namespace, or create a new one.
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: Nasal namespace problem with XML nasal/load script

Postby mhab » Tue Jul 05, 2016 9:00 pm

Hello

I tried closure() and got some output, but couldn't find any useful namespace to use ...

A carrier is an AI object and I would like to keep the nasal functions used within the vinson.xml file.

Mike-DE
mhab
 
Posts: 418
Joined: Thu Apr 18, 2013 11:59 pm
Callsign: D-MIKE
Version: 2020.3.4
OS: Win10

Re: Nasal namespace problem with XML nasal/load script

Postby Hooray » Tue Jul 05, 2016 9:13 pm

Like I said, you can use a workaround by using explicit namespaces referring to globals - however, I would suggest to look up the namespace used by those model scripts and then check if the namespace can be referenced from those bindings or not - the wiki has a few really tutorials covering Nasal namespaces, you may want to take a look at those to understand how they work.
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU


Return to Development

Who is online

Users browsing this forum: No registered users and 9 guests