I'm assigning some keys to rotate some model parts. I need to clamp the rotation between 265 and -265. (I saw a clamp function but let's leave that be for now.)
In my -set.xml I have the following code to limit the rotation. The first key (f/102) works fine. But the second key (F/70) would need a '<' which messes up the xml parsing. Rather than have messy, repetitive xml with CDATAs thrown about, I'd like to create a separate *.nas file with a generic function.
- Code: Select all
...
<!--Turret Rotation -->
<key n="102"> <!-- 102=f 70=F 114=r 82=R-->
<name>f</name>
<desc>Rotate forward turret to port</desc>
<repeatable type="bool">true</repeatable>
<binding>
<command>nasal</command>
<script>
var prop = "/sim/model/fore-turret-bearing-deg";
var value = getprop(prop);
value = value == nil? 0 : value + 1;
value = value > 265 ? 265 : value;
setprop(prop, value);
</script>
</binding>
</key>
<key n="70"> <!-- 102=f 70=F 114=r 82=R-->
<name>F</name>
<desc>Rotate forward turret to starboard</desc>
<repeatable type="bool">true</repeatable>
<binding>
<command>nasal</command>
<script>
turrets.rotate_turret("/sim/model/fore-turret-bearing-deg");
</script>
</binding>
</key>
...
<nasal>
<turrets>
<file>Aircraft/USS_Olympia/Nasal/turrets.nas</file>
</turrets>
</nasal>
</PropertyList>
Here's the contents of turrets.nas:
- Code: Select all
#functions for handling the turrets
print("Loaded turrets.nas");
var rotate_turret = func(prop) {
var value = getprop(prop);
value = value == nil? 0 : value - 1;
value = value < -265 ? -265 : value;
setprop(prop, value);
};
In sim, this results in "Nasal runtime error: undefined symbol: turrets"
Which makes me think that either FG isn't reading in turrets.nas or it's a name space issue. I don't think the <turrets> tags are strictly necessary. Wouldn't just including turrets.nas create a 'turrets' name space? In any case, I get the same results with and without the <turrets> tag. If I leave the turrets. out of the function call I get an undefined symbol error on 'rotate_turret'.
The file path is: '/home/jeff/FlightGear/Aircraft/USS_Olympia/Nasal/turrets.nas'.
What blindingly obvious thing am I missing?
TIA
--jeff