Howto talk:Development of the CDU

From FlightGear wiki
Revision as of 22:31, 2 December 2010 by Hooray (talk | contribs) (sorry, typo - you are of course right ( http://www.w3schools.com/xml/xml_cdata.asp ) - btw :I also added a reply to the bindings page, too.)
Jump to navigation Jump to search

Nasal in XML files (command bindings)

Note that Nasal scripts embedded in XML should be wrapped in <![CDATA[ ... ]]> markup:

 <![CDATA[ print("Foo");  ]]>

--Hooray 21:42, 2 December 2010 (UTC)

Thanks for that advice. But shouldn't there be a > somewhere? Could you please correct this example (in a new version below)?

<animation> 
	<type>pick</type>
	<object-name>Btn.zero</object-name>
	<action>
		<button>0</button>
		<repeatable>false</repeatable>  
		<binding>
			<command>nasal</command>
			<script><![CDATA[
                         setprop("/instrumentation/cdu/input",getprop("/instrumentation/cdu/input")~'0');
                       ]]></script>
		</binding>
	</action>
</animation>

--Hcc23 22:16, 2 December 2010 (UTC)

Implementing LSK logics

"The most cumbersome buttons are the line select keys. As their function depends on the current state of the CDU, 
 the corresponding XML requires some conditional checks."

I think, we actually talked about this previously on the forums. Instead of using lots of nested XML logics to model a CDU (or any complex instrument), it is actually better to just use the property tree for communicating "events" (e.g. button presses). This would then make it possible for a Nasal script to handle ALL logics (using a registered listener), so that a FSM (finite state machine) can be implemented in Nasal space, this is more flexible than a purely XML-based approach, and could also be more easily reused by other aircraft and developers. My personal suggestion would be to refrain from modeling advanced logics in XML space, while it is certainly possible to do so to a certain degree, the corresponding building blocks are relicts from an era where Nasal scripting was not yet available.--Hooray 22:31, 2 December 2010 (UTC)


Loading external Nasal files from XML files

There is code to do this in $FG_ROOT/Nasal/io.nas - namely the function "load_nasal(filename, namespace)". io.nas contains some comments. Basically, this allows you to reference/load and run separate Nasal modules, without having to embed all of the code directly in the XML markup. So it's a good practice and makes things easier:

 <binding>
 <command>nasal<command>
 <script><![CDATA[
    io.load_nasal("lsk.nas","lsk");
 ]]></script>
 </binding>

--Hooray 22:31, 2 December 2010 (UTC)