Board index FlightGear Development Nasal

cockpit-view: from --config format to --addon format

Nasal is the scripting language of FlightGear.

cockpit-view: from --config format to --addon format

Postby wkitty42 » Sun Aug 13, 2017 8:10 pm

i'm trying to convert the cockpit-view mod from the original --config format to the new --addon format... i should be able to split the original xml file into two parts...

1. put the propertytree data into the config.xml.
2. put all the nasal code into the main.nas file with the registration call in main().

i've done this but had different problems so i reverted and faked it by basically just renaming cockpit-view.xml to config.xml and creating a main.nas with an empty main() function... i'm not happy with that so i'm going to start this again from the beginning and do it like i was originally...

this topic is to help me figure out why i get the errors i do so i can correct them and get this addon working in the new addon space...
"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: 4686
Joined: Fri Feb 20, 2015 3:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 14.04.5

Re: cockpit-view: from --config format to --addon format

Postby Hooray » Sun Aug 13, 2017 8:12 pm

I'd suggest, you post the corresponding errors :-)

Apart from that, like I mentioned in the other thread (spoken ATC), you should be able to get a handle to the active namespace using caller() and closure() and then use debug.dump() to see how to get a handle to the namespace that you want/need.

If in doubt, use this:
http://wiki.flightgear.org/Nasal_Namespaces_in-depth
Image
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: 11124
Joined: Tue Mar 25, 2008 8:40 am

Re: cockpit-view: from --config format to --addon format

Postby AndersG » Sun Aug 13, 2017 8:28 pm

Is it the keyboard bindings that is the problem?

I suppose you might be able to just add

globals["model-cockpit-view"].model_view_handler = model_view_handler;

at the end of the main() function (after view.manager.register("Model Cockpit View", model_view_handler); which I suppose would be the only other thing in the main function). The bindings have to be able to find the code and publishing it under a fixed name is one way to do that. Of course if whatever else uses the same top-level name there would be problems...
Callsign: SE-AG
Aircraft (uhm...): Submarine Scout, Zeppelin NT, ZF Navy free balloon, Nordstern, Hindenburg, Short Empire flying-boat, ZNP-K, North Sea class, MTB T21 class, U.S.S. Monitor, MFI-9B, Type UB I submarine, Gokstad ship, Renault FT.
AndersG
 
Posts: 2413
Joined: Wed Nov 29, 2006 9:20 am
Location: Göteborg, Sweden
Callsign: SE-AG
OS: Debian GNU Linux

Re: cockpit-view: from --config format to --addon format

Postby wkitty42 » Sun Aug 13, 2017 8:48 pm

Hooray wrote in Sun Aug 13, 2017 8:12 pm:I'd suggest, you post the corresponding errors :-)

i'm fixing to... i'm trying to write this and clean up the files that i have so i can start posting the errors :lol:
i've got forty-leven windows open and finding the proper one on which of my eight desktops is a bear :mrgreen:
"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: 4686
Joined: Fri Feb 20, 2015 3:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 14.04.5

Re: cockpit-view: from --config format to --addon format

Postby wkitty42 » Sun Aug 13, 2017 8:53 pm

Hooray wrote in Sun Aug 13, 2017 8:12 pm:Apart from that, like I mentioned in the other thread (spoken ATC), you should be able to get a handle to the active namespace using caller() and closure() and then use debug.dump() to see how to get a handle to the namespace that you want/need.

yes, you did mention that but it doesn't mean anything to me... maybe in the future it will but for now it is gibberish ;) all i know about nasal is just what is in the files i'm currently working with and trying to decipher so i can correlate it to a language i do know and understand... i'm an old PASCAL and ASM guy but have been dug into PYTHON these last several days trying to figure out why my terrasync.py was failing so my head is pretty twisted right now :)
"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: 4686
Joined: Fri Feb 20, 2015 3:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 14.04.5

Re: cockpit-view: from --config format to --addon format

Postby wkitty42 » Sun Aug 13, 2017 9:14 pm

AndersG wrote in Sun Aug 13, 2017 8:28 pm:Is it the keyboard bindings that is the problem?

nope... it may be due to me reformatting for cleanliness and clarity... i can't find an editor that allows me to collapse nasal codeblocks so i can see the actual flow and close things up so i can see matching brackets and braces and the like...

Code: Select all
Initializing addon from /home/myuser/myflightgear/Addons/cockpit-view/main.nas in __addon[0]__
Parse error: parse error
  at /home/myuser/myflightgear/Addons/cockpit-view/main.nas, line 76
 :
 at /home/myuser/flightgear-dev/fgdata-ng/Nasal/io.nas, line 84
  called from: /home/myuser/flightgear-dev/fgdata-ng/Nasal/addons.nas, line 21
Nasal runtime error: bad/missing argument to call()
  at /home/myuser/flightgear-dev/fgdata-ng/Nasal/addons.nas, line 24


and here's lines 67 thru 79... i've run into this thing with the less than character several times already... it may be an editor problem...

Code: Select all
    next : func(v) {
        if (!me.active or !size(me.models))
            return;
        if (v)
            me.current += v;
        else
            me.current = 0;
     
        me.list = sort(keys(me.models), cmp);
        if (me.current &lt; 0)          <==== error here because of &lt; instead of <
            me.current = size(me.list) - 1;
        elsif (me.current >= size(me.list))
            me.current = 0;


so having corrected that to be a real "<" character, loading again gives me this...

Code: Select all
Initializing addon from /home/myuser/myflightgear/Addons/cockpit-view/main.nas in __addon[0]__
Nasal runtime error: foreach enumeration of non-vector
  at /home/myuser/flightgear-dev/fgdata-ng/Nasal/view.nas, line 117
  called from: /home/myuser/flightgear-dev/fgdata-ng/Nasal/view.nas, line 212
  called from: /home/myuser/myflightgear/Addons/cockpit-view/main.nas, line 113
  called from: /home/myuser/flightgear-dev/fgdata-ng/Nasal/addons.nas, line 24


i had thought it was related to this following codeblock which is the first foreach i see in the cockpit-view nasal code... now that i see the error better because of posting it here, it is apparently pointing to something completely different...

Code: Select all
    start : func {
        me.models = {};
        var ai = props.globals.getNode("/ai/models", 1);
        foreach (var m; [props.globals]
                        ~ ai.getChildren("aircraft")
                        ~ ai.getChildren("carrier")
                        ~ ai.getChildren("multiplayer")
                        ~ ai.getChildren("tanker")
                        ~ ai.getChildren("groundvehicle"))
            me.models[m.getPath()] = m;


so i don't know what the loader is crying about... the nasal code is not showing up in the property tree's /nasal branch but i don't think it will now because of the name spaces stuff... i AM seeing /sim/view[97000] with the "Model Cockpit View" name so the xml is apparently loading and it is only the nasal stuff that's giving problems...

so let's start with that and see how far we can go... what else do we need to see??
"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: 4686
Joined: Fri Feb 20, 2015 3:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 14.04.5

Re: cockpit-view: from --config format to --addon format

Postby wkitty42 » Sun Aug 13, 2017 9:55 pm

now that i've had a minute and a beverage of the adult type, looking at the error message again...

Code: Select all
Initializing addon from /home/myuser/myflightgear/Addons/cockpit-view/main.nas in __addon[0]__
Nasal runtime error: foreach enumeration of non-vector
  at /home/myuser/flightgear-dev/fgdata-ng/Nasal/view.nas, line 117
  called from: /home/myuser/flightgear-dev/fgdata-ng/Nasal/view.nas, line 212
  called from: /home/myuser/myflightgear/Addons/cockpit-view/main.nas, line 113
  called from: /home/myuser/flightgear-dev/fgdata-ng/Nasal/addons.nas, line 24


points me to the following where the view.manager.register call is line 113...
Code: Select all
var main = func( root ) {
    view.manager.register("Model Cockpit View", model_view_handler);
} # func main()


so i'm guessing that i need to change that last part from "model_view_handler" to something else???
"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: 4686
Joined: Fri Feb 20, 2015 3:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 14.04.5

Re: cockpit-view: from --config format to --addon format

Postby wkitty42 » Sun Aug 13, 2017 10:18 pm

so more rooting and digging about and i notice in the property tree that a lot of nasal is loaded in nasal files named in the property tree instead of actual script in the property tree... hummm... ok, so we use io.load_nasal() to do that... a quick edit to put all the nasal into view_handler.nas like it was in the original file, including the view.manager.register call... then change main() to be
Code: Select all
var main = func( root ) {
    io.load_nasal("view_handler.nas");
} # func main()


so now i get, half expectedly, the following error...
Code: Select all
Initializing addon from /home/myuser/myflightgear/Addons/cockpit-view/main.nas in __addon[0]__
Cannot stat file: view_handler.nas:
 at /home/myuser/flightgear-dev/fgdata-ng/Nasal/io.nas, line 4
  called from: /home/myuser/flightgear-dev/fgdata-ng/Nasal/io.nas, line 84
  called from: /home/myuser/myflightgear/Addons/cockpit-view/main.nas, line 84


so the question now is how do i tell main() what the path is to the file when it could be located anywhere on the file system?

i half expected this error because i couldn't be so lucky as to have the system load it from the current directory where the script is loaded from... granted, the path is in "/addons/addon/path" but that could be "/addons/addon[27]/path" the next time it is loaded...

is there something like self.location where i could do something like this?
Code: Select all
var main = func( root ) {
    io.load_nasal(self.location("view_handler.nas"));
} # func main()


/me goes off back into the deep deep woods digging and rooting around some more...
"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: 4686
Joined: Fri Feb 20, 2015 3:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 14.04.5

Re: cockpit-view: from --config format to --addon format

Postby wkitty42 » Sun Aug 13, 2017 10:49 pm

ok... main.nas now looks like this...

Code: Select all
var model_cockpit_view_root = nil;
var model_cockpit_view_dir = "";

var model_cockpit_view_init = func(root) {
    print("Cockpit View initializing...");
    # default values
    model_cockpit_view_root = root;
    model_cockpit_view_dir = sprintf("%s/", model_cockpit_view_root);
    print("  model_cockpit_view directory is " ~ model_cockpit_view_dir );
}

var main = func( root ) {
    model_cockpit_view_init(root);
    print("  attempting to load " ~ model_cockpit_view_dir ~ "view_handler.nas");
    io.load_nasal(model_cockpit_view_dir ~ "view_handler.nas");
    print("Cockpit View loaded and initialized.");
} # func main()


i swiped the init stuff from ATCChatter... so we got loading the nasal file done but we're back to our previous error...
Code: Select all
Initializing addon from /home/wkitty42/myflightgear/Addons/cockpit-view/main.nas in __addon[0]__
Cockpit View initializing...
  model_cockpit_view directory is /home/myuser/myflightgear/Addons/cockpit-view/
  attempting to load /home/myuser/myflightgear/Addons/cockpit-view/view_handler.nas
foreach enumeration of non-vector:
 at /home/myuser/flightgear-dev/fgdata-ng/Nasal/view.nas, line 117
  called from: /home/myuser/flightgear-dev/fgdata-ng/Nasal/view.nas, line 212
  called from: /home/myuser/myflightgear/Addons/cockpit-view/view_handler.nas, line 102


which is right back to...
Code: Select all
    view.manager.register("Model Cockpit View", model_view_handler);

so something isn't right with this call when used in this new --addon context...
"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: 4686
Joined: Fri Feb 20, 2015 3:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 14.04.5

Re: cockpit-view: from --config format to --addon format

Postby wkitty42 » Mon Aug 14, 2017 1:12 am

aww, GEEZ, Louise! really?? i finally got it to load... my switching to io.load_nasal was, apparently, a right move... at some point, after digging through a lot of code, my eyes uncrossed and i noted some calls were of the form...
Code: Select all
io.load_nasal("some_file.nas","some_prop_tree_location");

so i fixed up my io.load_nasal() call to add "model_view_handler" like the view.manager.register call was using and BAM! there it was...
Code: Select all
io.load_nasal(model_cockpit_view_dir ~ "view_handler.nas","model_view_handler");

all loaded in the property tree as /nasal/model_view_handler...

now i am going to go back up to AndersG's post and see if that helps with the key bindings as that is where my error is now when i activate the model cockpit viewer...

/me goes off to get another adult beverage, first, though :mrgreen:
"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: 4686
Joined: Fri Feb 20, 2015 3:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 14.04.5

Re: cockpit-view: from --config format to --addon format

Postby wkitty42 » Mon Aug 14, 2017 1:30 am

:sigh: well, i tried adding
Code: Select all
globals["model-cockpit-view"].model_view_handler = model_view_handler;

after
Code: Select all
io.load_nasal(model_cockpit_view_dir ~ "view_handler.nas","model_view_handler");

but i'm getting this error now...
Code: Select all
Nasal runtime error: non-objects have no members
  at /home/myuser/myflightgear/Addons/cockpit-view/main.nas, line 40
  called from: /home/myuser/myflightgear/Addons/cockpit-view/main.nas, line 46
  called from: /home/myuser/flightgear-dev/fgdata-ng/Nasal/addons.nas, line 26

line 40 IS the above added globals[] line :|

i am NOT seeing "model_view_handler" in the /nasal property tree like the original --config form was doing... in fact, even though it is loading properly (no errors are reported), i can't find it in the property tree... not as code stuffed into the tree or as a file noted as being loaded... without the globals[] line, i get these errors when trying to use the key bindings so obviously the code isn't being loaded or found where it is expected to be :(
Code: Select all
Nasal runtime error: non-objects have no members
  at /input/keyboard/key[113]/binding, line 1
"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: 4686
Joined: Fri Feb 20, 2015 3:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 14.04.5

Re: cockpit-view: from --config format to --addon format

Postby wkitty42 » Mon Aug 14, 2017 2:17 am

arrrrgh! this, from the wiki, does not make any sense... it is like the terms have been changed... what, exactly, does ""module"" mean???? it is a branch in the property tree or what?? if it is a namespace, then change "module" to "namespace" so that it makes sense...

load_nasal()

io.load_nasal(file[, module]);

Loads and executes a given Nasal script into a namespace.

file: Full path to the Nasal file as a string.
module : Optional name of module to load the script into as a string. If not given, the namespace will be the name of the file.

Examples
For the examples, first put the below code in to a new file, $FG_HOME/Export/demo.nas:
Code: Select all
var sayHello = func(){
    print("Hello, World!");
}

Code: Select all
var file = getprop("/sim/fg-home") ~ '/Export/demo.nas';
io.load_nasal(file); # load into "demo" namespace
demo.sayHello(); # "Hello, World!" will be printed

Code: Select all
var file = getprop("/sim/fg-home") ~ '/Export/demo.nas';
io.load_nasal(file, "myDemo"); # load into "myDemo" namespace
myDemo.sayHello(); # "Hello, World!" will be printed



i've been looking at the SpokenATC code and i'm still trying to figure out how/where they are getting the property tree /nasal/spokenatc/ branch created from because that's what i think needs to be done here with this mod because this mod's original code loaded the nasal into /nasal/model-cockpit-view but as raw nasal code in the script key... what i want to do with using io.load_nasal, is load the nasal code in the same place but instead of raw code in the script key, show the file loaded in the file key... and where does that loaded key come from???

then there's the matter of "-" and "_" which are driving sane people to commit seppuku... where, why and how does "this_is_my_prop_branch" get turned into "this-is-my-prop-branch" when it is written to the property tree???

in case i didn't say it earlier, ARRRRRRRRGH!!!
"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: 4686
Joined: Fri Feb 20, 2015 3:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 14.04.5

Re: cockpit-view: from --config format to --addon format

Postby Hooray » Mon Aug 14, 2017 4:19 pm

Sorry, I think you may be getting lost in irrelevant details - many of the things you mentioned in your recent postings don't seem likely to be the actual culprit to me.
Thus, my suggestion would be to share what you have by now, so that we can take a look ?

PS: There are editors that support syntaxhighlighting for Nasal, as well as code folding - see the wiki for details.
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: 11124
Joined: Tue Mar 25, 2008 8:40 am

Re: cockpit-view: from --config format to --addon format

Postby wkitty42 » Mon Aug 14, 2017 7:01 pm

Hooray wrote in Mon Aug 14, 2017 4:19 pm:PS: There are editors that support syntaxhighlighting for Nasal, as well as code folding - see the wiki for details.

been there, done that... no joy... i even installed gedit and the nasal.lang file but no code folding...

how many editors does one need?
Code: Select all
/usr/bin/debugedit
/usr/bin/desktop-file-edit
/usr/bin/edit
/usr/bin/edit-patch
/usr/bin/editcap
/usr/bin/editdiff
/usr/bin/editor
/usr/bin/editres
/usr/bin/elfedit
/usr/bin/gdal_edit.py
/usr/bin/gedit
/usr/bin/gnome-text-editor
/usr/bin/grub-editenv
/usr/bin/keditbookmarks
/usr/bin/keditfiletype
/usr/bin/kincidenceeditor
/usr/bin/kmenuedit
/usr/bin/mcedit
/usr/bin/photolayoutseditor
/usr/bin/policyeditor
/usr/bin/samba-regedit
/usr/bin/select-editor
/usr/bin/sensible-editor
/usr/bin/sieveeditor
/usr/bin/sudoedit
/usr/bin/x86_64-linux-gnu-elfedit
/usr/bin/xedit
/usr/lib/debug/usr/bin/keditfiletype
/usr/lib/debug/usr/bin/kmenuedit
/usr/lib/grass64/bin/v.edit

that's not even counting Kate and others that don't have "edit" in their names :shock: :roll:
"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: 4686
Joined: Fri Feb 20, 2015 3:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 14.04.5

Re: cockpit-view: from --config format to --addon format

Postby wkitty42 » Mon Aug 14, 2017 7:19 pm

ok, so here's the latest edition of the code...

config.xml
Code: Select all
<?xml version="1.0"?>
<!--
This file is part of the FlightGear cockpit-view addon.

The cockpit-view addon is free software: you can redistribute it
and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation, either version 2 of
the License, or (at your option) any later version.

cockpit-view is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this addon.  If not, see <http://www.gnu.org/licenses/>.
-->

<PropertyList>
  <sim>
    <view n="97000">
      <name>Model Cockpit View</name>
      <type>lookfrom</type>
      <config>
        <from-model type="bool">false</from-model>
        <from-model-idx type="int">0</from-model-idx>

        <at-model type="bool">false</at-model>
        <at-model-idx type="int">0</at-model-idx>

        <eye-lat-deg-path>/sim/viewer/eye/latitude-deg</eye-lat-deg-path>
        <eye-lon-deg-path>/sim/viewer/eye/longitude-deg</eye-lon-deg-path>
        <eye-alt-ft-path>/sim/viewer/eye/altitude-ft</eye-alt-ft-path>
        <eye-heading-deg-path>/sim/viewer/eye/heading-deg</eye-heading-deg-path>
        <eye-pitch-deg-path>/sim/viewer/eye/pitch-deg</eye-pitch-deg-path>
        <eye-roll-deg-path>/sim/viewer/eye/roll-deg</eye-roll-deg-path>

        <ground-level-nearplane-m type="double">0.2f</ground-level-nearplane-m>
        <default-field-of-view-deg type="double">65.0</default-field-of-view-deg>

        <x-offset-m type="double">0</x-offset-m>
        <y-offset-m type="double">0</y-offset-m>
        <z-offset-m type="double">0</z-offset-m>
        <heading-offset-deg>0</heading-offset-deg>
        <pitch-offset-deg>0</pitch-offset-deg>
        <roll-offset-deg>0</roll-offset-deg>
      </config>
    </view>

    <viewer>
      <eye>
        <latitude-deg type="double">0</latitude-deg>
        <longitude-deg type="double">0</longitude-deg>
        <altitude-ft type="double">0</altitude-ft>
        <heading-deg type="double">0</heading-deg>
        <pitch-deg type="double">0</pitch-deg>
        <roll-deg type="double">0</roll-deg>
      </eye>

      <target>
        <latitude-deg type="double">0</latitude-deg>
        <longitude-deg type="double">0</longitude-deg>
        <altitude-ft type="double">0</altitude-ft>
        <heading-deg type="double">0</heading-deg>
        <pitch-deg type="double">0</pitch-deg>
        <roll-deg type="double">0</roll-deg>
      </target>
    </viewer>
  </sim>

  <input>
    <keyboard>
      <key n="81">
        <name>Q</name>
        <desc>Switch to previous model</desc>
        <binding>
          <command>nasal</command>
          <script>globals["model-cockpit-view"].model_view_handler.next(-1)</script>
        </binding>
      </key>

      <key n="113">
        <name>q</name>
        <desc>Switch to next model</desc>
        <binding>
          <command>nasal</command>
          <script>globals["model-cockpit-view"].model_view_handler.next(1)</script>
        </binding>
      </key>
    </keyboard>
  </input>
</PropertyList>



main.nas
Code: Select all
# This file is part of the FlightGear cockpit-view addon.
#
# The cockpit-view addon is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation, either version 2 of
# the License, or (at your option) any later version.
#
# cockpit-view is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this addon.  If not, see <http://www.gnu.org/licenses/>.

# This is the main addon Nasal hook. It MUST contain a function
# called "main". The main function will be called upon init with
# the file system path pointing to the addon installation directory
# on your hard disk
#
# This script will live in it's own Nasal namespace that gets
# dynamically created from the global addon init script.
# It will be something like "__addon[n]__" where n is a positive integer
#

var model_cockpit_view_root = nil;
var model_cockpit_view_dir = "";

var model_cockpit_view_init = func(root) {
    print("Cockpit View initializing...");
    model_cockpit_view_root = root;
    model_cockpit_view_dir = sprintf("%s/", model_cockpit_view_root);
    print("  model_cockpit_view directory is " ~ model_cockpit_view_dir );
    print("  attempting to load " ~ model_cockpit_view_dir ~ "view_handler.nas");
    io.load_nasal(model_cockpit_view_dir ~ "view_handler.nas","model_cockpit_view");
    # how can i determine if io.load_nasal has an error or not???
    # this next line really should be in an if/then statement in case io.load_nasal has an error
    print("Cockpit View loaded and initialized.");
}


var main = func( root ) {
    model_cockpit_view_init(root);
} # func main()



view_handler.nas
Code: Select all
# This file is part of the FlightGear cockpit-view addon.
#
# The cockpit-view addon is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation, either version 2 of
# the License, or (at your option) any later version.
#
# cockpit-view is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this addon.  If not, see <http://www.gnu.org/licenses/>.

var model_view_handler = {
    init : func {
        me.models = {};
        me.list = [];
        me.current = 0;
        me.active = 0;
    },
    start : func {
        me.models = {};
        var ai = props.globals.getNode("/ai/models", 1);
        foreach (var m; [props.globals]
                        ~ ai.getChildren("aircraft")
                        ~ ai.getChildren("carrier")
                        ~ ai.getChildren("multiplayer")
                        ~ ai.getChildren("tanker")
                        ~ ai.getChildren("groundvehicle"))
            me.models[m.getPath()] = m;

        me.lnr = [];
        append(me.lnr, setlistener("/ai/models/model-added", func(n) {
            var m = props.globals.getNode(n.getValue(), 1);
            me.models[m.getPath()] = m;
        }));
        append(me.lnr, setlistener("/ai/models/model-removed", func(n) {
            var m = props.globals.getNode(n.getValue(), 1);
            delete(me.models, m.getPath());
        }));
        me.active = 1;
        me.reset();
    },
    update : func {
        return 0;
    },
    stop : func {
        me.active = 0;
        foreach (var listener; me.lnr)
            removelistener(listener);
    },
    reset : func {
        me.next(me.current);
    },
    next : func(v) {
        if (!me.active or !size(me.models))
            return;
        if (v)
            me.current += v;
        else
            me.current = 0;
     
        me.list = sort(keys(me.models), cmp);
        if (me.current < 0)
            me.current = size(me.list) - 1;
        elsif (me.current >= size(me.list))
            me.current = 0;

        var s = "/sim/view[97000]/config";
        var c = me.list[me.current];
        setprop(s, "eye-lat-deg-path", c ~ "/position/latitude-deg");
        setprop(s, "eye-lon-deg-path", c ~ "/position/longitude-deg");
        setprop(s, "eye-alt-ft-path", c ~ "/position/altitude-ft");
        setprop(s, "eye-heading-deg-path", c ~ "/orientation/true-heading-deg");
        setprop(s, "eye-pitch-deg-path", c ~ "/orientation/pitch-deg");
        setprop(s, "eye-roll-deg-path", c ~ "/orientation/roll-deg");

        var n = me.models[me.list[me.current]];
        var type = n.getName();
        var name = nil;
        if (type == "") {
            if (name = getprop("/sim/multiplay/callsign"))
                name = 'callsign "' ~ name ~ '"';
        } else {
            if ((name = n.getNode("callsign")) != nil and (name = name.getValue()))
                name = 'callsign "' ~ name ~ '"';
            elsif ((name = n.getNode("name")) != nil and (name = name.getValue()))
                name = n.getName() ~ ' "' ~ name ~ '"';
            else
                name = n.getName() ~ " " ~ n.getIndex();
        }
        var color = {};
        if (type != "multiplayer")
            color = { text: { color: { red: 0.5, green: 0.8, blue: 0.5 }}};
        if (name)
            gui.popupTip(name, 2, color);
    },
}; # var model_view_handler

#print("  attempting to register model_view_handler");
view.manager.register("Model Cockpit View", model_view_handler);
#print("  attempt to complete");



and the errors... they only appear when i actually switch to the cockpit_view and try to switch to other craft using the Q/q keys... each hit of the Q/q keys outputs the error...
Code: Select all
Initializing addon from /home/wkitty42/myflightgear/Addons/cockpit-view/main.nas in __addon[0]__
Cockpit View initializing...
  model_cockpit_view directory is /home/wkitty42/myflightgear/Addons/cockpit-view/
  attempting to load /home/wkitty42/myflightgear/Addons/cockpit-view/view_handler.nas
Cockpit View loaded and initialized.
[...]
Nasal runtime error: non-objects have no members
  at /input/keyboard/key[113]/binding, line 1
Nasal runtime error: non-objects have no members
  at /input/keyboard/key[81]/binding, line 1
"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: 4686
Joined: Fri Feb 20, 2015 3:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 14.04.5

Next

Return to Nasal

Who is online

Users browsing this forum: No registered users and 2 guests