chrisdev01 Posted June 26, 2018 Report Posted June 26, 2018 Hello: I am just starting to scratch the surface of using Lua scripts with FSUIPC. I am trying to solve a problem with the Milviz C310 where the prop condition levers do not move into the feather range using my CH Products throttle quadrant. Despite accurate calibration, moving the hardware prop levers aft of the detents does not move the software levers into the feather range, nor does the prop feather animation get displayed. Instead, the Milviz C310 requires users to right-click the prop lever knobs to feather the props. My current calibration does work for other default and payware prop aircraft. In an effort to have the C310 props go into the feather range using my quadrant, I tried using the FSUIPC Axis Assignments GUI to stack two ranges to the prop levers, aft of the detents, to assign the commands: ~ PROP_PITCH1_SET (with a parameter of -1) ~ TOGGLE_FEATHER_SWITCH_1 After doing so, when I move the hardware prop lever aft of the detent, I can see the commands being set using the FSUIPC log as expected; but the animation in the sim does not move the condition levers to the feather range, and the prop feather animation is not displayed. On the Milviz support forum, the aircraft's developer provided a snippet of right mouse click event code that checks a boolean L variable called Prop1_Feathered. The Prop1_Feathered variable represents the feather animation. If the Prop1_Feathered variable is false, then PROP_PITCH1_SET is set to -1 and the TOGGLE_FEATHER_SWITCH_1 command is called, else the reciprocal values are set. This is done for both the left and the right engines. From Milviz: if{ (L:Prop1_Feathered,bool) ! if { 1 (>L:Prop1_Feathered,bool) -1 (>K:PROP_PITCH1_SET) (>K:TOGGLE_FEATHER_SWITCH_1) } els{ 0 (>L:Prop1_Feathered,bool) 0 (>K:PROP_PITCH1_SET) (>K:TOGGLE_FEATHER_SWITCH_1) } } So it seems I need to script the following: If prop 1 axis range is between two values (aft of hardware detent), then set variable L:Prop1_Feathered to true set PROP_PITCH1_SET -1 toggle TOGGLE_FEATHER_SWITCH_1 When leaving the prop 1 axis feather range (forward of hardware detent), then set variable L:Prop1_Feathered to false set PROP_PITCH1_SET 0 toggle TOGGLE_FEATHER_SWITCH_1 I'm not sure, but the latter part of the logic may not be necessary as I suspect that existing Milviz code will set the prop as soon as I move out of the feathered range - will need to test this. Based on what I've read, I think I am supposed to use the FSUIPC GUI to reference a script file, that I create in the Modules folder, that gets called when the axis range is entered or exited. I also suppose that my script file could have a function/method like FeatherProp(int) that accepts one variable: ~ int EngineNumber So my pseudo code might look something like this: FeatherProp(EngineNumber(int) { Feathered bool; if (EngineNumber == 1) { //Getting the current value of the Prop1_Feathered animation variable will likely look something like this Feathered = ipc.readLvar(“Prop1_Feathered”); //Setting the reciprical of the current “Prop1_Feathered” variable may look like this ipc.writeLvar("Prop1_Feathered", !Feathered); //Calling the Toggle Feather Switch command might look like this ipc.control("TOGGLE_FEATHER_SWITCH_1"); if(!Feathered) { //Setting the prop pitch might look like this ipc.control("PROP_PITCH1_SET", -1); } else { ipc.control("PROP_PITCH1_SET", 0); } } else { //Getting the current value of the Prop2_Feathered variable will likely look something like this Feathered = ipc.readLvar(“Prop2_Feathered”); //Setting the reciprocal of the current “Prop2_Feathered” variable may look like this ipc.writeLvar("Prop2_Feathered", !Feathered); //Calling the Toggle Feather Switch command might look like this ipc.control("TOGGLE_FEATHER_SWITCH_2"); if(!Feathered) { //Setting the prop pitch might look like this ipc.control("PROP_PITCH2_SET", -1); } else { ipc.control("PROP_PITCH2_SET", 0); } } } As you can see, I'm a C# developer, so my pseudo code looks nothing like Lua script yet, I still need to work that part out... I have a few questions regarding key concepts of Lua scripting: Generally speaking, am I on the right track from a conceptual standpoint? Can the variable L:Prop1_Feathered (mentioned by the aircraft's developer) be referenced by name in my script, or do I need to log the variables running in the sim and reference the variable using some returned int or hex that represents the L:Prop1_Feathered animation variable? How do I reference my script file using the FSUIPC GUI? Specifically, how do I call my script file's FeatherProp() method passing in the engine number parameter when my hardware prop lever is aft of the detent? On the Axis assignment tab? Am I using the correct IPC commands to read and set my L variable? Am I using the correct IPC commands to set my prop pitch values? Am I using the correct IPC commands to toggle my feather switches? Thank you for your patience as I try to code my first Lua script. Sincerely, Chris
Pete Dowson Posted June 26, 2018 Report Posted June 26, 2018 4 minutes ago, chrisdev01 said: Can the variable L:Prop1_Feathered (mentioned by the aircraft's developer) be referenced by name in my script, or do I need to log the variables running in the sim and reference the variable using some returned int or hex that represents the L:Prop1_Feathered animation variable? LVars are only known by name, as should be clear from the FSUIPC Lua Library document entry for it! Please do check that document. As it says, you can include the L: part or omit it. 7 minutes ago, chrisdev01 said: How do I reference my script file using the FSUIPC GUI? Specifically, how do I call my script file's FeatherProp() method passing in the engine number parameter when my hardware prop lever is aft of the detent? On the Axis assignment tab? Yes, assign the axis to the Lua:<name> entry in the fropdown. If it is only for certain part of the range you'd need to do this on the right-hand side of the axis assignments tab. But bear in mind that Lua plug-ins are loaded, compiled, and run, each time you call them UNLESS you pre-load them and use events instead of calling them explicitly. Ths might be a consideration if your axis is sending lots of changes, but isn't so important for "one-off" actions. 11 minutes ago, chrisdev01 said: Am I using the correct IPC commands to read and set my L variable? Am I using the correct IPC commands to set my prop pitch values? Am I using the correct IPC commands to toggle my feather switches? I'm not going to check your pseudo-code. Sorry. Please use the reference materials provided. There's quite clear syntax detailed in the Lua documents, and plenty of examples. Note that numbers are NOT "names" and vice versa. Built-in Sim events ("controls") for setting axis values and operating switches are actually NUMBERS and a complete list is provided for you. The names are used in the drop-downs and correspond to those in the list, but you must use numbers in programming them in Lua. Please do try looking at the examples, and relate them to the Lua Library reference documentation. I don't provide Lua language reference or help. That is part of the Lua documentation and reference on the Lua website. There are also some excellent books on Lua, including one called "Beginning Lua Programming". And a reference called "Lua Reference Manual", but the latter tells you no more than the same stuff on the website. Lua is subtly different from Basic, C, C# etc. But being a script-style language and compiled each time used, it is easy to debug. You can make changes, try again, until you get it right, very quickly -- no need to keep reloading the Sim. So write your first Lua plug-in, and try it. Errors will be logged, in the FSUIPC log file or optionally in its own file, and there's a trace facility too (both options are in the Logging tab in FSUIPC). Pete
chrisdev01 Posted June 28, 2018 Author Report Posted June 28, 2018 Pete: Got it working with a couple of simple scripts. Thank you very much for your help! Chris
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now