I have found that the logic and code to control a fuel selector control is much more difficult that I expected. The screenshot below shows the type of fuel valve I was trying to model. It can rotate around four positions for Both, right, off, then left. You would like it to grab with the mouse and drag around to each position and it fires the event to set that tank as the active. But I tried so many different methods to achieve this.
So the problem is that the index numbers for the tanks are not in a sequential order, so you need to remap any incremental value of the switch position to the appropriate tank indexes. Here's how I solved it so far.
I added two planes to accept the mouse clicks. The material is invisible with collision.
This is the code for each side.
The tooltip shows what the next selection will be if you click. But the tricky part is the code section. I'm using a case statement which is very oddly specified in RPN style. 0 1 3 3 4 (A:FUEL TANK SELECTOR:1, Enum) case (>K:FUEL_SELECTOR_SET)
The last number before the simvar (4) indicates how many cases there are. The cases are 0 1 3 3. When (A:FUEL TANK SELECTOR:1, Enum) is 0, the case operator returns 0. When it's 1, it returns 1. If 2, return 3 and if 3, return 3.
The animation of the lever is pretty easy and has the same trick.
When (A:FUEL TANK SELECTOR:1, Enum) is 0, return 3, 1 = 1, 2 = 0 and 3 = 2. Then multiply by 100 to match the 400 frame animation in Blender.
I'm curious to see if anyone else has solved this type of problem and if it's possible to have a similar logic with a freely draggable control.
So the problem is that the index numbers for the tanks are not in a sequential order, so you need to remap any incremental value of the switch position to the appropriate tank indexes. Here's how I solved it so far.
I added two planes to accept the mouse clicks. The material is invisible with collision.
This is the code for each side.
XML:
<Component ID="Fuel_Select_CW" Node="Fuel_Select_CW">
<UseTemplate Name="ASOBO_GT_Interaction_LeftSingle_Code">
<!-- eval the current tank ID and show which tank will be selected next -->
<TOOLTIPID>Set Fuel to
%(( A:FUEL TANK SELECTOR:1, Enum) 0 ==)%{if}RIGHT%{else}
%(( A:FUEL TANK SELECTOR:1, Enum) 1 ==)%{if}RIGHT%{else}
%(( A:FUEL TANK SELECTOR:1, Enum) 2 ==)%{if}BOTH%{else}OFF%{end}
</TOOLTIPID>
<CURSOR>RightArrow</CURSOR>
<!-- 4 cases = if 0(off):3(right), 1(all):3(right), 2(left):1(on), 3(right):0(off) -->
<LEFT_SINGLE_CODE>0 1 3 3 4 (A:FUEL TANK SELECTOR:1, Enum) case (>K:FUEL_SELECTOR_SET)</LEFT_SINGLE_CODE>
<EVENTID/>d
</UseTemplate>
</Component>
<Component ID="Fuel_Select_CCW" Node="Fuel_Select_CCW">
<UseTemplate Name="ASOBO_GT_Interaction_LeftSingle_Code">
<!-- eval the current tank ID and show which tank will be selected next -->
<TOOLTIPID>Set Fuel to
%(( A:FUEL TANK SELECTOR:1, Enum) 0 ==)%{if}LEFT%{else}
%(( A:FUEL TANK SELECTOR:1, Enum) 1 ==)%{if}LEFT%{else}
%(( A:FUEL TANK SELECTOR:1, Enum) 2 ==)%{if}OFF%{else}BOTH%{end}
</TOOLTIPID>
<CURSOR>LeftArrow</CURSOR>
<!-- 4 cases = if 0(off):3(left), 1(all):2(left), 2(left):0(off), 3(right):1(on) -->
<LEFT_SINGLE_CODE>1 0 2 2 4 (A:FUEL TANK SELECTOR:1, Enum) case (>K:FUEL_SELECTOR_SET)</LEFT_SINGLE_CODE>
<EVENTID/>
</UseTemplate>
</Component>
The tooltip shows what the next selection will be if you click. But the tricky part is the code section. I'm using a case statement which is very oddly specified in RPN style. 0 1 3 3 4 (A:FUEL TANK SELECTOR:1, Enum) case (>K:FUEL_SELECTOR_SET)
The last number before the simvar (4) indicates how many cases there are. The cases are 0 1 3 3. When (A:FUEL TANK SELECTOR:1, Enum) is 0, the case operator returns 0. When it's 1, it returns 1. If 2, return 3 and if 3, return 3.
The animation of the lever is pretty easy and has the same trick.
Code:
<Component ID="FUEL_Switch_Selector" Node="FUEL_Switch_Selector">
<UseTemplate Name="ASOBO_GT_Anim">
<ANIM_NAME>FUEL_Switch_Selector</ANIM_NAME>
<!-- frame 0=1(all) frame 100=2(left) frame 200=0(off) frame 300=3(right) -->
<ANIM_CODE>3 1 0 2 4 (A:FUEL TANK SELECTOR:1, Enum) case 100 *</ANIM_CODE>
<ANIM_LENGTH>400</ANIM_LENGTH>
<ANIM_WRAP>TRUE</ANIM_WRAP>
<ANIM_LAG>300</ANIM_LAG>
</UseTemplate>
</Component>
When (A:FUEL TANK SELECTOR:1, Enum) is 0, return 3, 1 = 1, 2 = 0 and 3 = 2. Then multiply by 100 to match the 400 frame animation in Blender.
I'm curious to see if anyone else has solved this type of problem and if it's possible to have a similar logic with a freely draggable control.