Howto:Control the route manager in Nasal: Difference between revisions

Jump to navigation Jump to search
m
Fix internal wiki links
(Switch to {{fg root file}} to fix the broken Gitorious link.)
m (Fix internal wiki links)
 
Line 9: Line 9:
So the route manager dialog only provides a convenient interface, you could just as well use the property browser or Nasal directly.
So the route manager dialog only provides a convenient interface, you could just as well use the property browser or Nasal directly.


Properties can be set from Nasal using the setprop() command: http://wiki.flightgear.org/Nasal#setprop.28.29
Properties can be set from Nasal using the setprop() command: [[Nasal library#setprop()]]


In order to set a property to a certain value/string, you just use a piece of code like the following:
In order to set a property to a certain value/string, you just use a piece of code like the following:
Line 28: Line 28:
Now you need to make sure that the undefined "next" variable actually contains sensible and comprehensible input for the route manager system (see the RM wiki page).
Now you need to make sure that the undefined "next" variable actually contains sensible and comprehensible input for the route manager system (see the RM wiki page).


To work with a list of pre-defined coordinates, you could use a Nasal vector: http://wiki.flightgear.org/Nasal#Variables
To work with a list of pre-defined coordinates, you could use a Nasal vector: [[Nasal Variables]]


The following piece of code declares and initializes an empty vector in Nasal:
The following piece of code declares and initializes an empty vector in Nasal:
Line 61: Line 61:
Note that indexing starts at 0 and not at 1 !
Note that indexing starts at 0 and not at 1 !


Next, you would need to register a function that gets called during startup, so that it can keep setting the route manager, this is done using a _setlistener() call: http://wiki.flightgear.org/Nasal#setlistener.28.29
Next, you would need to register a function that gets called during startup, so that it can keep setting the route manager, this is done using a _setlistener() call: [[Nasal library#setlistener()]]


Note that the underscore (_) is important, because the low level function (not he wrapper) must be used here:
Note that the underscore (_) is important, because the low level function (not he wrapper) must be used here:
Line 67: Line 67:
     _setlistener("/sim/signals/nasal-dir-initialized", myCode);
     _setlistener("/sim/signals/nasal-dir-initialized", myCode);


To ensure that your code gets called repeatedly, at a fixed rate - you need to use a settimer() call: http://wiki.flightgear.org/Nasal#settimer.28.29
To ensure that your code gets called repeatedly, at a fixed rate - you need to use a settimer() call: [[Nasal library#settimer()]]




As you can see at http://wiki.flightgear.org/Route_manager_internals there is even direct support for re-sequencing a route by setting the current-waypoint index to a different waypoint number in the route.
As you can see at [[Route manager internals]] there is even direct support for re-sequencing a route by setting the current-waypoint index to a different waypoint number in the route.


<syntaxhighlight lang="php">
<syntaxhighlight lang="php">
Line 86: Line 86:
When added to $FG_ROOT/Nasal/rm_control.nas, this piece of code will get called at 5 second intervals and keeps adding yet another "SFO" waypoint to the RM route.
When added to $FG_ROOT/Nasal/rm_control.nas, this piece of code will get called at 5 second intervals and keeps adding yet another "SFO" waypoint to the RM route.


Obviously, this is not yet very useful - but when you take another look at http://wiki.flightgear.org/Route_manager_internals#Signals you'll see that the RM system also emits so called "signals" by setting a certain property when specific events (such as route re-sequencing) occur. So you could now register a listener to this property and keep setting the property to the next "position" in the vector:
Obviously, this is not yet very useful - but when you take another look at [[Route manager internals#Signals]] you'll see that the RM system also emits so called "signals" by setting a certain property when specific events (such as route re-sequencing) occur. So you could now register a listener to this property and keep setting the property to the next "position" in the vector:


<syntaxhighlight lang="php">
<syntaxhighlight lang="php">

Navigation menu