20,741
edits
Line 1,085: | Line 1,085: | ||
last_step_time = time; | last_step_time = time; | ||
} | } | ||
</syntaxhighlight> | |||
The most relevant/interesting part being the foreach loop where all targets are processed: | |||
<syntaxhighlight lang="nasal"> | |||
foreach (var t; node.getChildren()) { | |||
var lon = t.getNode("longitude-deg"); | |||
var lat = t.getNode("latitude-deg"); | |||
if (lon == nil or lat == nil) | |||
die("target coords undefined"); | |||
var target = geo.Coord.new().set_latlon(lat.getValue(), lon.getValue()); | |||
# ... | |||
} | |||
</syntaxhighlight> | |||
We can easily turn this into a new helper function: | |||
<syntaxhighlight lang="nasal"> | |||
var getTargets = func(node) { | |||
var results = []; | |||
foreach (var t; node.getChildren()) { | |||
var lon = t.getNode("longitude-deg"); | |||
var lat = t.getNode("latitude-deg"); | |||
if (lon == nil or lat == nil) | |||
die("target coords undefined"); | |||
var target = geo.Coord.new().set_latlon(lat.getValue(), lon.getValue()); | |||
append(results,target); | |||
} | |||
return results; | |||
} | |||
</syntaxhighlight> | </syntaxhighlight> | ||