20,741
edits
Line 140: | Line 140: | ||
== Moving huge conditionals into hash functions == | == Moving huge conditionals into hash functions == | ||
The next problem we want to tackle is getting rid of huge conditional blocks inside the '''update()''' method: {{Git link|gitorious|fg/fgdata|master|Aircraft/747-400/Models/Cockpit/Instruments/PFD/PFD.nas}} | |||
<syntaxhighlight lang="nasal" line="GESHI_FANCY_LINE_NUMBERS" start="258"> | |||
if(abs(deflection) < 0.5) { # need to verify 0.5 | |||
locPtr.setTranslation(deflection*300,0); | |||
risingRwyPtr.setTranslation(deflection*300,0); | |||
locScaleExp.show(); | |||
locScale.hide(); | |||
} else { | |||
locPtr.setTranslation(deflection*150,0); | |||
risingRwyPtr.setTranslation(deflection*150,0); | |||
locScaleExp.hide(); | |||
locScale.show(); | |||
} | |||
</syntaxhighlight> | |||
Such conditionals can be usually spit into: | |||
* condition (predicate) | |||
* body if true | |||
* body if false | |||
== Configuration == | == Configuration == |