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

Stumped by {case}

Messages
1,564
Country
thailand
Hello,

I’m trying to create a string based on an enum value.

The enum is (C:fs9gps:FlightPlanWaypointType) and the string is either 'UNKN', 'AIRPORT', 'INTERSECTION', 'VOR', 'NDB', or 'USER' depending upon the value of the enum.

My application is not a formatted text situation where the following {case} syntax works:

Code:
<String>
%((C:fs9gps:FlightPlanWaypointType))%{case}%{:0}UNKN%{:1}AIRPORT%{:2}INTERSECTION%{:3}VOR%{:4}NDB%{:5}USER%{end}
</String>

But rather, a LOGGER application:

Code:
:101
(L:WaypointsWritten,enum) (>C:fs9gps:FlightPlanWaypointIndex)

(C:fs9gps:FlightPlanWaypointType) [COLOR="Red"]Something {case}[/COLOR] (>C:LOGGER:string)

(L:WaypointsWritten,enum) 1 + (>L:WaypointsWritten,enum)
(L:WaypointsWritten,enum) (C:fs9gps:FlightPlanWaypointsNumber) &lt; if{ g101 }

where Something {case} is where I hoped to make use of {case} to create the appropriate string – in one line of script.

The following works, but requires multiple if{ statements:
Code:
:101
(L:WaypointsWritten,enum) (>C:fs9gps:FlightPlanWaypointIndex)

(C:fs9gps:FlightPlanWaypointType) 0 == if{ ‘UNKN’ (>C:LOGGER:string) }
(C:fs9gps:FlightPlanWaypointType) 1 == if{ ‘AIRPORT’ (>C:LOGGER:string) }
(C:fs9gps:FlightPlanWaypointType) 2 == if{ ‘INTERSECTION’ (>C:LOGGER:string) }
(C:fs9gps:FlightPlanWaypointType) 3 == if{ ‘VOR’ (>C:LOGGER:string) }
(C:fs9gps:FlightPlanWaypointType) 4 == if{ ‘NDB’ (>C:LOGGER:string) }
(C:fs9gps:FlightPlanWaypointType) 5 == if{ ‘USER’ (>C:LOGGER:string) }

(L:WaypointsWritten,enum) 1 + (>L:WaypointsWritten,enum)
(L:WaypointsWritten,enum) (C:fs9gps:FlightPlanWaypointsNumber) &lt; if{ g101 }

What is the proper syntax using {case} to do the same as those 6 if{ statements? I’ve worked it for hours but the answer still escapes me.

Any solutions? Thanks in advance.

Bob
 
The only example I have found of a use of {case} outside of a <String> statement is this one found in the <Update> section of the default gps_500.xml file:
Code:
<!-- calculate CDI range -->
	0.3 1 5 0.001 4 (@g:modeCDI) case (@g:scaleCDI) s0 0.1 &gt; if{ l0 - 0.002 min -0.002 max l0 + } (&gt;@g:scaleCDI)

Based on this structure, my "best guess" for your need would be:
Code:
'USER' 'NDB' 'VOR' 'INTERSECTION' 'AIRPORT' 'UNKN' 6 case (C:fs9gps:FlightPlanWaypointType) (>C:LOGGER:string)
 
Thank you Bill,

That's what I was looking for! Didn't work at first but I switched the order of the operator and the argument (case and FlightPlanWaypointType) and it works well - much more pleasing than the if statements.

Code:
'USER' 'NDB' 'VOR' 'INTERSECTION' 'AIRPORT' 'UNKN' 6 (C:fs9gps:FlightPlanWaypointType) case (>C:LOGGER:string)

You know, case is in the SDK, which I consulted, yet obviously I had something wrong until now.

Thank you again. Merry Christmas and Sawasdee pee mai

Bob
 
Cool beans! So my guess was at least close after all. I have never actually had occasion to use this myself, but it's nice to know the correct formula now.

Mele Kalikimaka dear friend!
 
Sawasdee Bob,

If you take a look at the XMLVarsExample.xml file that comes inside XMLVars1nn.zip, you'll find good examples on how to use case statement within advanced code.

Tom
 
Sawasdee Bob,

If you take a look at the XMLVarsExample.xml file that comes inside XMLVars1nn.zip, you'll find good examples on how to use case statement within advanced code.

Tom

That's true! And I see it now that you reminded me about that XML example. I just didn't think to look at it before :o

In fact, I note that your LoadDispReferences macro has a few similarities to my application – e.g., selecting string data and used within a loop.

It also reminds me how advanced some of your macros can be with things like @@2Vars 10 l0 case sp10 which I don’t understand at first. Efficient for you but complex for me. :)

Khop khun makk khrab Khun Tom

Bob
 
Back
Top