Ok, someone with a little Java background knowledge will not have much of a problem picking up basic FlightGear scripting/Nasal concepts.
Nasal really is a simple language, much simpler than Java/JavaScript - it does not even do OOP the way it is done in Java.
If you want to do Canvas stuff, you will sooner or later encounter OOP though.
The main thing to keep in mind here is that most things go through the property tree.
So, do make sure to understand the property tree itself (unrelated to Nasal scripting), as well as the setprop/getprop extension functions and the higher level props.nas module which provides an OO wrapper around the whole thing.
For that, you will definitely want to tinker a bit with a few Nasal/OOP tutorials - again, the wiki is your friend here.
The key thing to keep in mind: Nasal has no constructors or destructors, there also is no "class" keyword.
Instead, we have hash maps - i.e. dictionaries that have key/value pairs, using a comma-separated list of key/value pairs (untested pseudo code below):
- Code: Select all
var someHash = {
x: 100,
y: 200,
z: 300,
};
This is a hash that has 3 members: x,y,z - they can be accessed via:
- Code: Select all
someHash.x
someHash.y
someHash.z
You can assign arbitrary values to these keys, including strings, but also functions:
- Code: Select all
var someHash = {
x: func() {return 100;},
y: func() {return 200;},
z: func() {return 300;},
};
Next, inheritance is accomplished by using a single Nasal specific keyword only, called
parents.
This can be a hash-specific vector containing a list of other hashes for the member/field (method) lookup, i.e. serving as a template:
- Code: Select all
var someHash = {
x: func() {return 100;},
y: func() {return 200;},
z: func() {return 300;},
};
var someNewHash = { parents:[someHash] };
At this point, someNewHash is inherited from someHash.
Most commonly, this is done using a pseudo constructor that we name "new", i.e. a key/value pair where new is the key, and a func is the value, usually this also gets a matching pseudo-destructor, that is commonly named "del":
- Code: Select all
var someOtherHash = {
new: func() {
return {parents:[someHash]};
},
del: func() {
},
};
With your sort of background, everything should fall into place once you do a little more reading, and some experiments with different tutorials and code snippets - and again, leave anything alone that is aircraft specific, there is too much complex stuff happening that is unrelated to Nasal the language.
For starters, all you will need to know can be learned via the wiki, the forum and a few tutorials - if in doubt, just ask your questions here, and people will usually be quick to post an answer.
I would also definitely suggest using just the Nasal Console and REPL for starters - it will all make much more sense, I would only look at creating separate files, once you understand the language and extensions mechanisms well enough - otherwise there are literally dozens of potential pitfalls where things can go wrong, despite using correct code
My suggestion would be do little "assignments" first before digging into the more complicated stuff, i.e. things like:
- make flightgear print "Hello World" to the console
- make flightgear print "Hello World" 5 times using a loop (try different kinds of loops)
- try putting 5 names into a vector (array) or hash and make FlightGear print that to the console using a loop
- set a value in the property tree from a Nasal string
- get(prop) a value from the property tree and read it back into a Nasal string
- write a function that accepts a vector and writes all its elements to the console
- do it again, this time with a hash
- make it accept a list of properties, and write the values in the tree to the console
This is really basic stuff, and while it may sound complicated, most people around here who have a little Nasal coding can complete all of these in under 10 minutes - but it will go a long way to help provide the foundation for some of the more sophisticated concepts, especially anything involving OOP and Canvas stuff.
Anyway, good luck