Custom variables (like LVars), but unique to each SimObject

Hi everyone,

I am developing some unique functionality with my SimObjects, and I am in need of custom variables that behave like L:Vars, (accessible to SimConnect, XML model behavior code, and in-game dialog interface JS/HTML code), but are still unique to each SimObject.

For example, I need a custom variable on a SimObject, let’s call it “MyVar”, that will trigger a specific animation. It needs to be a unique variable to that SimObject, so that, if I spawn 2 instances of the SimObject, their MyVars are unique.

I can utilize L:Vars, however, their global nature would apply to all SimObjects that employ them. For example, if I tied a L:Var to triggering SimObject’s certain animation, and if I set that LVar to true, all the SimObject instances would have the animation triggered.

I’ve found some promising material in the SDK reference for Reverse Polish Notation, especially “Z var”, which is described as a “Object sim’s scoped Custom Sim var”, but I think it applies only to RPN code, and is not exposed to SimConnect.

Any suggestions or insight into this would be appreciated!

Mitch
TerraBuilder Team

It would be of course cool, waiting for this for a long time, I need to open/close the doors of my Simconnect spawned cable cars, and using a Lvar is no option because it will open all the doors even for moving cars too lol :laughing:

(Maybe a duplicate of this

How to access scoped LVars (L:1:) with SimConnect - #24 by B21)

According to the new vars APIv2 seems to be possible to set Zvar too (as well as all other types) with wasm (so we don’t need Simconnect?) however the possible targets are only user and avatar.

So to my understanding, without the ability to set a specific SimobjectID in the function call, it makes it useless in this case, and that’s a pity because they worked hard on this new API

Oh, pitty! That would have helped, but since they are applicable only to user object, that’s a non starter…

If I understood correctly, that’s what L:1: vars do in MSFS2024. They don’t exist in 2020 though.

@mamuDesign I had a wild idea… the trick is to find a SimVar (or preferably a set of variables (SimVars)) that any category SimObjects other than “Aircraft” category are using, and “hijack” them for our own purposes.

Do you know if it is possible to access SIMCONNECT_DATA_WAYPOINT array in XML (in the behaviors, etc. sections) ? JS can access it through Coherent.call(“GET_FLIGHTPLAN”), but I am not sure how to pass this to XML.

Basically, most SimObjects can be given a flight plan (GroundVehicles, Animals, Boats, FlyingAnimals…). This flight plan activates (SimObject starts to follow it) as soon as you pass it to SimObject. However, if you freeze your object, the flight plan is still scoped to SimObject, but not being used. So, you can use the waypoint list array, basically, as your aggregate for as many variables as you need. And since each SIMCONNECT_DATA_WAYPOINT has 6 members (5 doubles and one ulong), this gives you 5x more data per array member.

I can do this in WASM/SimConnect, but I am not sure how to pass this data to XML code, the way XML code can read SimVars (including LVars). Any thoughts on this?

1 Like

Hi @mamuDesign , and everyone!

I’ve solved this particular “problem”, albeit, by using a hack :wink: . After tinkering and experimenting, I’ve discovered that there are 6 SimVars that can be “hijacked” and set to ANY category of SimObject, even the simplest type “StaticObject”. Provided that you are using “FREEZE” command SimConnect (or equivalent in JS/XML) on your SimObjects (which I am assuming you are, in order to control your cable cars), you can use these 6 SimVars:

“ROTATION ACCELERATION BODY X”
“ROTATION ACCELERATION BODY Y”
“ROTATION ACCELERATION BODY Z”
“VELOCITY BODY X”
“VELOCITY BODY Y”
“VELOCITY BODY Z”

These SimVars are settable, and you can use them for anything you need in your XML (trigger animations, visibility, etc), and sim will ignore them IF, as I mentioned, you are using FREEZE commands to set your own SimObject positions and orientations.

Internally, ”StaticObject” category is probalby a parent class to all other SimObjects, so these 6 variables will be available to ALL SimObject categories. However, if you are NOT "freezing” positions and orientations, you could probably declare your SimObject as some other category, say, “GroundVehicle”, and then get access to a few more “hijackable” SimVars, specific to that category (which are specified in SDK somewhere). Anyway, that is the premise. I tried the above and it works well, suitable for my needs.

Also - the above variables can be used as whole numerical values, which is a bit of a waste if you just need a toggle (true/false) switch. And, since they are all 64-bit variables, you can actually multiplex them (use them as a bank of 64 true/false switches). So, in theory, these 6 variables can become an array of 6x64=384 true/false switches, available for anything you wish on the SimObject. I tried this (in FSX/P3D, but I don’t see a reason it wouldn’t work in MSFS202x), but multiplexing (bit setting) was done in C++/WASM, and I have no idea how to do it in JS/XML. However, CHECKING the bits can be done in XML, so that you can use them in <Behaviors> blocks and such.

I hope this helps,
Misho
TerraBuilder team

2 Likes