• 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.

MSFS Write random value 0 or 1 in xml

Messages
54
Country
spain
Greetings,

I've modded an aircraft to be AI stationary version and works fine. But now I would like the aircraft sometimes spawns with the main door open, and sometimes closed, randomly. The animation that control it in the original version aircraft is:
XML:
<UseTemplate Name="ASOBO_GT_Anim_Code" Node="MAIN_DOOR">
    <ANIM_NAME>MAIN_DOOR_ANIM</ANIM_NAME>
    <ANIM_LENGTH>1</ANIM_LENGTH>
    <ANIM_CODE>(L:MAIN_DOOR_POS, number) 100 /</ANIM_CODE>
</UseTemplate>

I discovered that if I write <ANIM_CODE>1</ANIM_CODE> the aircraft spawns with the door open, and <ANIM_CODE>0</ANIM_CODE> closed.

How can we generate the 0 or the 1 randomly?

I've tried the RPN random mentioned in SDK but I think I don't use it properly. It's a bit confusing for me and didn't find examples how to use it in this case https://docs.flightsimulator.com/html/Additional_Information/Reverse_Polish_Notation.htm?rhhlterm="rand rand"

Thanks in advance
 
Last edited:
Messages
135
Country
ukraine
Getting one random value of rand is quite possible to implement this, but with a smaller range of cases.
For example, when initializing a device in which there is a description of the logic, you can do this.
XML:
(L:Init, bool) 0 == if{ rand (&gt;L:door, number) }
(L:door, number) 0 != if{ 1 (&gt;L:Init, bool) }
(L:Init, bool) 1 == if{ (L:door, number) 0.5 &gt;= if{ 1 (&gt;L:MAIN_DOOR_POS, number) } els{ 0 (&gt;L:MAIN_DOOR_POS, number) } }

It is also possible to set many more conditions for time, time of day, weather, type of parking, etc.
In this case, it is not necessary to divide L:MAIN_DOOR_POS by 100 in <ANIM_CODE>
Wrote on the go did not check, but should work.
 
Last edited:
Messages
54
Country
spain
Hi thank you! Unfortunately the code always returns 0 and the door is always closed

1673434958785.png

1673435122317.png
 
Messages
54
Country
spain
This comand yes returns always 0 or 1 randomly, the problem is that the comand is running in every frame and the door is constantly opening and closing in miliseconds. Is there any way to freeze the animation?
1673435542622.png
 
Messages
16
Country
denmark
This comand yes returns always 0 or 1 randomly, the problem is that the comand is running in every frame and the door is constantly opening and closing in miliseconds. Is there any way to freeze the animation?
View attachment 85929
Hello,

Maybe you could try this:

XML:
<UseTemplate Name="ASOBO_GT_Anim_Code" Node="ASCRJ_MAIN_DOOR">
    <ANIM_NAME>ASCRJ_MAIN_DOOR</ANIM_NAME>
    <ANIM_LENGTH>1</ANIM_LENGTH>
    <ANIM_CODE>
    rand 0.5 >
    </ANIM_CODE>
    <ANIM_LAG>80</ANIM_LAG>
    <Code>(E:LOCAL TIME, Seconds) 30400 &gt;= (E:LOCAL TIME, Seconds) 39600 &lt;= and if{ 1 } els{ 0 }</Code>   
</UseTemplate>

The ANIM_LAG variable should slow down the animation.
The E:LOCAL TIME variable should in theory make the animation happen at the specific time period indicated only.

Best wishes,

Anna
 
Messages
54
Country
spain
Hi!

Sorry for the late I've been out of home some days.

I've tried it, the result it's the same. It full opens and full closes every frame randomly. Maybe is the comand "rand" that is built to be executed every frame, because if I write
XML:
<Component ID="main_door" Node="main_door">
    <UseTemplate Name="ASOBO_GT_Visibility_Code">
        <VISIBILITY_CODE>
            rand 0.5 >
        </VISIBILITY_CODE>           
    </UseTemplate>
</Component>
It also flickers every frame, and this time is not an animation... 🧐

Maybe the <animation> method is not the better in terms of performance, at a busy airport would be overkill for an AI object. Would it be better to use the <visibility> method for open/close the door? I that case, is it possible show a node in a specific position like for example the door opened?
 
Messages
54
Country
spain
This code always returns 0 or 1 depending the aircraft position, so if the aircraft is spawned some meters away, in theory, result should be different for each plane but...
XML:
<Component ID="main_door" Node="main_door">
    <UseTemplate Name="ASOBO_GT_Visibility_Code">
        <VISIBILITY_CODE>
            (A:PLANE LONGITUDE, Radians) (A:PLANE LATITUDE, Radians) % 4 symb 4 >
        </VISIBILITY_CODE>         
    </UseTemplate>
</Component>

The result, 0 or 1, is always the same for every aircraft spawned. Each AI aircraft spawned uses the result from the first spawned aircraft, why? I thought each object of the same model, would read the code individually.

Thanks in advance
 
Last edited:

DragonflightDesign

Resource contributor
Messages
1,082
Country
northernireland
You need to set a check flag to prevent multiple runs through the code. I don't do MSFS XML, so what follows is just the pseudo-code framework:
Code:
if (myCheckFlag = 0)
{
  myCheckFlag = 1;
  get the random number for open or close
  set the animation as required
}
My guess is that the code will be inside the <ANIM_CODE> tags.
 
Messages
54
Country
spain
Good idea! I suspect it will always start at the beginning inicializating myCheckFlag every frame, but definitely I'll try it (when I learn the correct sintax how to write it in RPN ) Thank you!
 
Messages
135
Country
ukraine
Good idea! I suspect it will always start at the beginning inicializating myCheckFlag every frame, but definitely I'll try it (when I learn the correct sintax how to write it in RPN ) Thank you!
It may be easier to write a WASM module for the necessary behavior calculations and animation of traffic details, it would be much easier to work with timing, random variables and duplicated objects there, after all, C ++ is a more flexible tool than xml.
 
Messages
54
Country
spain
It may be easier to write a WASM module for the necessary behavior calculations and animation of traffic details, it would be much easier to work with timing, random variables and duplicated objects there, after all, C ++ is a more flexible tool than xml.
Would be nice to know how to do that hehe

You need to set a check flag to prevent multiple runs through the code. I don't do MSFS XML, so what follows is just the pseudo-code framework:
Code:
if (myCheckFlag = 0)
{
  myCheckFlag = 1;
  get the random number for open or close
  set the animation as required
}
My guess is that the code will be inside the <ANIM_CODE> tags.
Seems it works! My problem is I think I'm not writing it properly:
XML:
<Code>
    (L:myCheckFlag, Bool) 0 == if{ (L:myCheckFlag, Bool) 1 rand 0.5 > }
</Code>

Looks like myCheckFlag is always 0 and "random" is running every frame
imagen.png

imagen.png


But if I write manually the value 1 for myCheckFlag, it works, the random stops!
imagen.png

imagen.png
 
Messages
54
Country
spain
Well finally a good solution. Don't tell me why but using the units "degree latitude" and "degree longitude" instead of radians, every spawned AI object, yes reads the code individually
😄


XML:
(A:PLANE LATITUDE, degree latitude) (A:PLANE LONGITUDE, degree longitude) % 5 symb 4 >
This returns 0 o or 1 depending the spawned AI plane position, so the door will be open or closed every stationary plane individually 😍

Thanks all for the help.
 
Last edited:
Messages
54
Country
spain
Now the last step, to write the code only once and call it by a variable. How to asign a value to a variable?

I thought this would work:
XML:
    <UseTemplate Name="xxx" Node="xxx">.....<ANIM_CODE>(L:myVariable, number) (A:PLANE LATITUDE, degree latitude) (A:PLANE LONGITUDE, degree longitude) % 5 symb 4 ></ANIM_CODE></UseTemplate>
    <UseTemplate Name="yyy" Node="yyy">.....<ANIM_CODE>(L:myVariable)</ANIM_CODE></UseTemplate>
    <UseTemplate Name="zzz" Node="zzz">.....<ANIM_CODE>(L:myVariable)</ANIM_CODE></UseTemplate>
    <UseTemplate Name="uuu" Node="uuu">.....<ANIM_CODE>(L:myVariable)</ANIM_CODE></UseTemplate>

Simplifying, for example, to inicialize myVariable to 1, Is this correct?
XML:
(L:myVariable,number) 1
So... Why I don't see 1 at all other <anim_code> tags?
XML:
<Component ID="Doors">
    <UseTemplate Name="xxx" Node="xxx">.....<ANIM_CODE>(L:myVariable, number) 1</ANIM_CODE></UseTemplate>
    <UseTemplate Name="yyy" Node="yyy">.....<ANIM_CODE>(L:myVariable)</ANIM_CODE></UseTemplate>
    <UseTemplate Name="zzz" Node="zzz">.....<ANIM_CODE>(L:myVariable)</ANIM_CODE></UseTemplate>
    <UseTemplate Name="uuu" Node="uuu">.....<ANIM_CODE>(L:myVariable)</ANIM_CODE></UseTemplate>
</Component>
 
Top