20,741
edits
Line 1,118: | Line 1,118: | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Now, let's use the c172p and the [[Nasal Console]] to see if our code works as expected: | |||
<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; | |||
} | |||
} | |||
if (tutorialN == nil) { | |||
screen.log.write('Unable to find tutorial "' ~ name ~ '"'); | |||
return nil; | |||
} | |||
} | |||
var tutorial = getTutorialNode("Taxiing"); | |||
var allTargets = nil; | |||
if (tutorial != nil) { | |||
allTargets = tutorial.getNode("targets"); | |||
} | |||
props.dump(allTargets); | |||
</syntaxhighlight> | |||
Once you start fgfs with the c172p, this snippet of code should load the "Taxiing" tutorial (it having a number of targets) and dump all info to the console: | |||
<syntaxhighlight lang="text"> | |||
targets {NONE} = nil | |||
targets/j1 {NONE} = nil | |||
targets/j1/longitude-deg {UNSPECIFIED} = -121.81664 | |||
targets/j1/latitude-deg {UNSPECIFIED} = 37.6949 | |||
targets/j2 {NONE} = nil | |||
targets/j2/longitude-deg {UNSPECIFIED} = -121.82258 | |||
targets/j2/latitude-deg {UNSPECIFIED} = 37.6949 | |||
targets/j3 {NONE} = nil | |||
targets/j3/longitude-deg {UNSPECIFIED} = -121.8250 | |||
targets/j3/latitude-deg {UNSPECIFIED} = 37.69498 | |||
targets/a1 {NONE} = nil | |||
targets/a1/longitude-deg {UNSPECIFIED} = -121.8251 | |||
targets/a1/latitude-deg {UNSPECIFIED} = 37.694616 | |||
targets/a2 {NONE} = nil | |||
targets/a2/longitude-deg {UNSPECIFIED} = -121.8294 | |||
targets/a2/latitude-deg {UNSPECIFIED} = 37.69459 | |||
</syntaxhighlight> | |||
Next, we need to come up with some boilerplate code for creating a new MapStructure layer, and then populate the searchCmd() method using our two helper fnctions | Next, we need to come up with some boilerplate code for creating a new MapStructure layer, and then populate the searchCmd() method using our two helper fnctions |