Canvas MapStructure: Difference between revisions

Jump to navigation Jump to search
m
Line 995: Line 995:
This section will cover the main steps for implementing a new layer whose purpose is showing all targets of a selectable [[Tutorials|tutorial]] on a Canvas/MapStructure map.
This section will cover the main steps for implementing a new layer whose purpose is showing all targets of a selectable [[Tutorials|tutorial]] on a Canvas/MapStructure map.


For starters, we need to take a look at $FG_ROOT/Nasal/tutorial/tutorial.nas to see how to get a list of targets:
For starters, we need to take a look at $FG_ROOT/Nasal/tutorial/tutorial.nas to see how to get a list of tutorials, so we open the corresponding file and search for '''tutorials''' and see this:
 
<syntaxhighlight lang="nasal">
tutorialN = nil;
        foreach (var c; props.globals.getNode("/sim/tutorials").getChildren("tutorial")) {
                if (c.getNode("name").getValue() == name) {
                        tutorialN = c;
                        break;
                }
        }
</syntaxhighlight>
 
As can be seen, this requires only a single variable: '''name''' - so we can easily turn this into a helper function:
 
<syntaxhighlight lang="nasal">
var getTutorialNode = func(name) {
var tutorialN = nil;
        foreach (var c; props.globals.getNode("/sim/tutorials").getChildren("tutorial")) {
                if (c.getNode("name").getValue() == name) {
                        tutorialN = c;
                        return tutorialN;
                }
        }
return nil;
}
</syntaxhighlight>


== Diagnostics ==
== Diagnostics ==

Navigation menu