• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

MSFS20 Xml logic for custome code

Messages
54
Country
italy
Hi everyone, I'm trying to add custom code to the choke lever of my airplane in developing for MSFS 2020 using Copilot's AI ( I'm not a coding expert ) , but every test doesn't give the desired result after compiling, (templates loaded but custom variables not showed in behaviordebug /LocalVariables.. etc ), I think perhaps that Copilot AI may have provided the correct logic, but the syntax and file paths may be incorrect. I would like to know if the basic structure is correct for implementing custom code.

In my PackageSources I have the following folder "ModelBehaviorDefs" and inside my xml.file called "custom_code.xml"

Questions:

1) MODEL.XML
Is the my "include" instruction right for my custom.xml file ? Is the sintax correct?

<Behaviors>
<Include ModelBehaviorFile="ModelBehaviorDefs\custom_code.xml"/>
..... etc ....

CUSTOM.XML

the first instructions of my generic "custom_code.xml" are right?

<?xml version="1.0" encoding="utf-8"?>
<ModelBehaviors>
<Template Name="test">
.......... custom code........
</Template>
</ModelBehaviors>

hope someone could help me to understand, or could explain me the right way to add custom code for custom behavior ( I mean how to initialize some custom templates , how to call it ) .
Thanks
 
Hi! There are many connection options. Here's one of them.
Location 1:
Your Airplane\PackageSources\ModelBehaviorDefs\Your Template Folder
Place the following there:
Includes.xml with the code
XML:
<ModelBehaviors>
<Include RelativeFile="custom_code.xml" />
</ModelBehaviors>
And the custom_code.xml file with the code
XML:
<ModelBehaviors>
<Template Name="test">
<!-- <custom code> -->
</Template>
</ModelBehaviors>

Inclusion:
XML:
<Include ModelBehaviorFile="Your Template Folder\Includes.xml"/>

<Component ID="Any name" <!-- + if required Node="custom node" --> >
<!-- <custom code> -->
<UseTemplate Name="test"/>
<!-- <custom code> -->
</Component>

AND
Your Airplane\\PackageDefinitions\****-****-****.xml

XML:
        <AssetGroup Name="ModelBehaviorDefs">
            <Type Version="0">Copy</Type>
            <Flags>
                <FSXCompatibility>false</FSXCompatibility>
            </Flags>
            <AssetDir>PackageSources\ModelBehaviorDefs\</AssetDir>
            <OutputDir>ModelBehaviorDefs\</OutputDir>
        </AssetGroup>
    </AssetGroups>
 
Last edited:
@Lyonya , sorry but I don't understand the first code:

<ModelBehaviors>
<Include RelativeFile="custom_code.xml" />
</ModelBehaviors>

where do I have to put it ? Perhaps in the custom code folder over my file custom_code.xml do I need to create another file.xml called Includes.xml ? the other codes are clear. Thanks
 
Last edited:
Why are you trying to include a custom code file?

The only reason you would need to use an include file is if you are going to use multiple instances of the code. It simply cuts down on duplicating code. There is no other advantage.

Unless there is a very specific reason (like needing to reuse the code multiple times as I said earlier) then you should add your custom code to either the interior or exterior .xml files as defined in your model.cfg in the model folder for your aircraft depending on which part it affects.

Perhaps if you were to post the code and where you need to insert it then we could advise how to insert it. Because there's no guarantee that what you have is going to work even if you get the include code correct.
 
2025-10-14_201415.jpg

Includes.xml
XML:
<ModelBehaviors>
<Include RelativeFile="custom_code.xml" />
</ModelBehaviors>

And yes, Anthony31 is absolutely right, if your template is used once, then there is no need to create inclusions of its templates in different components, then it is better to create a Component with parameters in the main Behaviors file of the model without transitions to included templates.
 
Thanks for reply to both, @Lyonya , @Anthony31 .
I've been developing my plane for three years. All the onboard systems works, all the instruments. The only thing that only works, let's say, "aesthetically" but has no realism or effect on the engine is the choke lever. For this function I used the Asobo template. Not being a coding expert, I wanted to give some realism to the choke. Everything that works on my plane, such as instruments and systems, works thanks to my patience in understanding what little I managed to understand of the pre-made XML codes of Asobo default aircrafts or Pay , doing tests, importing pieces of codes and adapting them to what I needed. Now that I would like to create a custom code to try to give realism to my choke lever, not being able, I had the brilliant idea of trying it with the helps of four different AIs. They all apparently come up with code after code, but when I go into the sim they does't work. I've seen the ModelBehaviorDefs folder in a couple of airplanes and thought it might be the right way to insert an XML file with the codes produced by the AI, but nothing of the proposed one works, except the custom template in my custom xml file visible in behavior but permanently at 0 and the variable that the AI told me to look for in LocalVariables at 1, was never there. This is because the AI, after seeing that its portions of code for real choke didn't work, gave me a whole series of tests like that, a template to check and a variable to look for. That's why I asked here for help. Thanks.
 
Got it. Then you will be interested in this MODEL BEHAVIORS INPUTS. This will give you the opportunity to create your own weight, and also to create templates and simulator changes, the type of influence not only on it, but also on physical control devices, joystick, controller, etc.
 
Back
Top