Working from wlbragg's generous code, I've tried to create a new property in my ship's xml file called "modltyp" ie:
- Code: Select all
<entry>
<type>carrier</type>
<name>FGS_Braunshweig</name>
<modltyp>boat</modltyp>
</entry>
I've done this because in some cases, "callsign" contains variables other than just "fleet". For example, in the vinson_demo, each ship has it's own unique callsign. The Vinson's is "Vinson", one of the escort's is "CG-57" and so on.
I had then edited wlbragg's most recent nasal code (not the array example) by replacing all instances of "callsign" with "modltyp" and "fleet" with "boat" as follows:
- Code: Select all
# main() ============================================================
#this requires that all ships have "<modltyp>boat</modltyp>" in their respective XML
var main_loop = func {
foreach(var shipN; props.globals.getNode("/ai/models", 1).getChildren("carrier")) {
{
if (string.match(shipN.getNode("modltyp").getValue(), "boat")) {
aiParent = shipN.getNode("modltyp").getParent().getName() ~ "[" ~ shipN.getNode("modltyp").getParent().getIndex() ~ "]";
var currentLat = props.globals.getNode("/ai/models/" ~ aiParent ~ "/latitude-deg").getValue();
var currentLon = props.globals.getNode("/ai/models/" ~ aiParent ~ "/longitude-deg").getValue();
var terrain_elev = geo.elevation(currentLat, currentLon);
props.globals.getNode("ai/models/" ~ aiParent ~ "/elevation-ft").setDoubleValue(terrain_elev);
}
}
settimer(main_loop, 10);
}
setlistener("/sim/signals/fdm-initialized", func {
main_loop();
});
Nope. Nada. No joy. Clearly, there must be more to it. Just as there's more to driving than careening from curb to curb...