The website and forum will be intermittently unavailable while we're making some security updates.
File uploads to the download hangar are also disabled until further notice.

XML for Newbies Part 1 - Basic Code Structure

The Tutorials forum section is the place where you can learn the various techniques that go into the creation of AI traffic packages.
Post Reply
User avatar
Weescotty
MAIW Developer
MAIW Developer
Posts: 2770
Joined: 11 Aug 2006, 22:15
Version: FS9
Location: Sydney

XML for Newbies Part 1 - Basic Code Structure

Post by Weescotty »

Welcome to the first part of our XML tutorials.
We do not claim any of these are unique in fact most have been gleaned from other sources like fsdeveloper and aerodynamika for example.
Firstly we will cover FS9, FSX has a different code structure but the essentials are the same.

a) Part Names!
YOUR_PART_NAME, YOUR_PART_NAME.1, YOUR_PART_NAME.6, YOUR_PART_NAME.any_other_name
As long as the name before the period (.) is the same, ALL would be controlled by a block of code for YOUR_PART_NAME
Very useful for animations where you need multple parts to move together!
Avoid using part names that are the same, or similar to part names already available.
I spent a long time trying to work out why some XML wasn't working, turned out AI_PROP_STILL was a little too similar to an actual FS9 part name.


b) FS9 Part Visibility Code Structure

<part>
<name>YOUR_PART_NAME</name>
<visible_in_range>
<parameter>
<code>
YOUR_CODE
</code>
</parameter>
<minvalue>YOUR_LOW_VALUE</minvalue>
<maxvalue>YOUR_HIGH_VALUE</maxvalue>
</visible_in_range>
</part>

NOTE:
You may may use
<minvalue>YOUR_LOW_VALUE</minvalue>
without needing to use
<maxvalue>YOUR_HIGH_VALUE</maxvalue>


c) FS9 Animation Code Structure

<part>
<name>YOUR_PART_NAME</name>
<animation>
<parameter>
<code>
YOUR_CODE
</code>
<lag>YOUR_LAG_VALUE</lag>
</parameter>
</animation>
</part>

NOTE: LAG_VALUE determines how fast the animation runs.


d) FS9 Combined Visibility / Animation Code Structure

<part>
<name>YOUR_PART_NAME</name>
<visible_in_range>
<parameter>
<code>
YOUR_VISIBILITY_CODE
</code>
</parameter>
<minvalue>YOUR_LOW_VALUE</minvalue>
<mavalue>YOUR_HIGH_VALUE</maxvalue>
</visible_in_range>
<animation>
<parameter>
<code>
YOUR_ANIMATION_CODE
</code>
<lag>YOUR_LAG_VALUE</lag>
</parameter>
</animation>
</part>
User avatar
Weescotty
MAIW Developer
MAIW Developer
Posts: 2770
Joined: 11 Aug 2006, 22:15
Version: FS9
Location: Sydney

Re: XML for Newbies Part 2 - Basic Visibility Codes

Post by Weescotty »

The SDK lists all variables that are available, however not all can be used for AI Aircraft.

a) Some common triggers for the <code> section.

(A:LIGHT NAV,bool) - comes on 15 mins before active, goes off 15 mins after shutdown.
(A:LIGHT BEACON,bool) - comes on just prior to taxi on engine start, goes off on shutdown.
(A:LIGHT STROBE,bool) - comes on after hold short, goes off when permission to leave runway is given.

NOTE:
bool can be substituted by number, in actual use it really makes no difference.


b) EXAMPLE 1 - Display A Part When A Light Is On

<part>
<name>IF_Light_nav_on</name>
<visible_in_range>
<parameter>
<code>
(A:LIGHT NAV,bool)
</code>
</parameter>
<minvalue>1</minvalue>
</visible_in_range>
</part>

For a part name called - IF_Light_nav_on
Code (A:LIGHT NAV,bool) - if on = TRUE or 1, if off = FALSE or 0
<minvalue>1</minvalue> - If the minimum value of the code section is 1 (TRUE) then show the part
When the Nav Light is off 0 (FALSE) is returned, this is less than the minimum value so the part is not visible.

NOTE:
Adding <maxvalue>1</maxvalue> below the <minvalue>1</minvalue> would also be correct, it just is not needed.



c) EXAMPLE 2 - What If You Want A Part To Display When A Light Is Off?

<part>
<name>IF_Light_strobe_off</name>
<visible_in_range>
<parameter>
<code>
(A:LIGHT STROBE,bool)
</code>
</parameter>
<minvalue>-1</minvalue>
<maxvalue>0</maxvalue>
</visible_in_range>
</part>

For a part name called - IF_Light_strobe_off
Code (A:LIGHT STROBE,bool) - if on = TRUE or 1, if off = FALSE or 0
For this we need BOTH a <minvalue> and <maxvalue> ... the maxvalue returned by the code would be 1 (light on)
BUT we dont want it to show so <maxvalue>0</maxvalue> says only display when light is off.
BUT with a <maxvalue> you must ALSO have a <minvalue> so you use -1
User avatar
Weescotty
MAIW Developer
MAIW Developer
Posts: 2770
Joined: 11 Aug 2006, 22:15
Version: FS9
Location: Sydney

Re: XML for Newbies Part 3 - Boolean Operations

Post by Weescotty »

To get more useful code you need to be able to understand Boolean Operations.
Plenty on the internet, but here is the basics.

a) and - can also use && or &amp;&amp;

AND - only when both sides are TRUE, is True the result.

1 AND 1 = 1 (True)
1 AND 0 = 0 (False)
0 AND 1 = 0 (False)
0 AND 0 = 0 (False)

AND - only when both sides are TRUE, is True the result.


b) or - can also use ||

OR - at least one side must be TRUE, for the result to be True

1 OR 1 = 1 (True)
1 OR 0 = 1 (True)
0 OR 1 = 1 (True)
0 OR 0 = 0 (False)


c) not - can also use !

NOT - 'flips' the result. TRUE becomes FALSE and vice versa

1 NOT = 0 (False)
0 NOT = 1 (True)


EXAMPLE - using the IF_Light_strobe_off code from the last post....

<part>
<name>IF_Light_strobe_off</name>
<visible_in_range>
<parameter>
<code>
(A:LIGHT STROBE,bool)
</code>
</parameter>
<minvalue>-1</minvalue>
<maxvalue>0</maxvalue>
</visible_in_range>
</part>

Using not, this can also be written as...

<part>
<name>IF_Light_strobe_off</name>
<visible_in_range>
<parameter>
<code>
(A:LIGHT STROBE,bool) !
</code>
</parameter>
<minvalue>1</minvalue>
</visible_in_range>
</part>

When (A:LIGHT STROBE,bool) returns OFF (false), ! makes it TRUE (1)
minvalue to display the part is 1, so the part is visible when the light is off.

When (A:LIGHT STROBE,bool) returns ON (true), ! makes it FALSE (0)
minvalue to display the part is 1, so the part is hidden when the light is on.
User avatar
Weescotty
MAIW Developer
MAIW Developer
Posts: 2770
Joined: 11 Aug 2006, 22:15
Version: FS9
Location: Sydney

Re: XML for Newbies Part 4 - Arithmetic Operators

Post by Weescotty »

Back to schooldays for us wrinklies....
Greater Than > , Less Than < , Equal to = , Not Equal to <>
You shouldn't use the above symbols in FS9 or FSX XML code, instead use...

a) Greater Than - &gt:
b) Less Than - &lt;
c) Equal To - ==
d) Not Equal To - !=
e) Greater Than or Equal To - &gt=;
f) Less Than or Equal To - &lt=;
User avatar
Weescotty
MAIW Developer
MAIW Developer
Posts: 2770
Joined: 11 Aug 2006, 22:15
Version: FS9
Location: Sydney

Re: XML for Newbies Part 4 - Reverse Polish Notation

Post by Weescotty »

Reverse Polish Notation (RPN) is probably the biggest thing you will need to get your head around as it is contrarary to the way you usually do calculations.
Plenty on the web on how it works, but here is the very basics....

a) What you are used to ... 1 + 2
in RPN is 1 2 +

The values are 'entered' before what you want to do with them.

b) Slightly more complicated ... 1 + (6 * 2)
in RPN is 6 2 * 1 +
or
because of the way the stack works can also be ... 1 6 2 * +

Lets see if I can explain it clearly, it drives me NUTS, using an old fashioned RPN calculator...

2 ENTER - STACK 1
6 ENTER - STACK 1 6
2 ENTER - STACK 1 6 2
* ENTER - * requires 2 values so uses the last two values on the stack which are 6 2 then puts the result back on the STACK 1 12
+ ENTER - + requires 2 values so uses the last two values on the stack which are 1 12 then puts the result back on the STACK 13
User avatar
Weescotty
MAIW Developer
MAIW Developer
Posts: 2770
Joined: 11 Aug 2006, 22:15
Version: FS9
Location: Sydney

Re: XML for Newbies Part 5 - if / els

Post by Weescotty »

For us programmers or casual coders this is easier....

a) An if / else loop is as follows (using x as a variable, syntax varies slightly between coding languages)...

If x = 1 Then <Do This>
Else <Do That>
EndIf

In our XML the syntax is slightly different and it has to be done with RPN in mind, so it becomes...

x 1 == if{ Do This } els{ Do That } <----- NOTE: els NOT else


In reality we wouldn't be using x 1 == but maybe something along the lines of...

(A:RADIO HEIGHT,feet) 100 &gt;
if{ 100 } els{ 0 }

So the code checks to see if the aircraft is over 100ft, if TRUE it would return 100, while FALSE i.e. it is under 100ft, it returns 0


b) Nesting if els...

Gets nutty keeping track of them but...

(A:RADIO HEIGHT,feet) 100 &gt;
if{ 100 } els{ (A:LIGHT LANDING,bool)
if{ 50 } els{ 0 } }

Does the same initial check as above, BUT if under 100ft then checks if the Landing Light is ON, if it is it returns 50, if OFF it returns 0

If your nested if els is not working there is a good chance that you are either missing of have an extra bracket in the somewhere.

V = Return Value

Test1 if{ V1 } els{ Test2 if{ V2 } els { Test3 if { V3 } els { Test4 if{ V4 } els{ V5 } } } } etc etc
User avatar
Weescotty
MAIW Developer
MAIW Developer
Posts: 2770
Joined: 11 Aug 2006, 22:15
Version: FS9
Location: Sydney

Re: XML for Newbies Part 6 - Lag Value

Post by Weescotty »

Been asked about the lag value for animations.
It is got from a calculation.

Number of keyframes / Lag value = Length of animation (in seconds)
Or
Lag value = Number of keyframes / Length of animation (in seconds)

So if you have 100 keyframes -
For a 10 second animation = 100 /10 = lag value 10
For a 5 second animation = 100 /5 = lag value 20

You will notice a HIGHER lag value results in a faster animation, contrary to what you would expect.
Post Reply