Jump to content
The simFlight Network Forums

Strange LVar Behaviour


Recommended Posts

Hi, i'm trying to create a lua script to control the switches of the a2a cessna 172, and so far all works except the window defrost control.

Monitoring the lua vars i've found that 3 vars are associated with that funcion (they change when i turn on/off the defrost via the mini-control panel of the aircraft) and they are:

 

WindowDefrosterControl1

WindowDefrosterControl2

WindowDefrosterControlKnob

 

I've wrote the code for toggling it on/off, but as i press the key associated with the lua script parameter it switches on/off for but immediately return to the previous state... 

 

Here's my script:

 

-- Windshield Defroster Toggle
if ipcPARAM == 4 then
 
    LVar1Set = "L:WindowDefrosterControl1"
    val1 = 0
 
    if ipc.readLvar(LVar1Set) == 0  then
    val1 = 25
    end
 
    LVar1Set = "L:WindowDefrosterControl2"
    val2 = 0
 
    if ipc.readLvar(LVar2Set) == 0  then
    val2 = 25
    end
 
    LVar3Set = "L:WindowDefrosterControlKnob"
    val3 = 0
 
    if ipc.readLvar(LVar3Set) == 0  then
    val3 = 100
    end
 
    ipc.writeLvar(LVar1Set, val1)
    ipc.writeLvar(LVar2Set, val2)
    ipc.writeLvar(LVar3Set, val3)
end
 
Something wrong with it? Monitoring lua I've found that it works in a very strange way, sometimes the knob value doesn't change at all, sometimes it sets at 50 instead of 100... the control1 and 2 seem to switch to 1 for a while but turning back to 0 immediately...
any clues? thank you!
Link to comment
Share on other sites

Something wrong with it? Monitoring lua I've found that it works in a very strange way, sometimes the knob value doesn't change at all, sometimes it sets at 50 instead of 100... the control1 and 2 seem to switch to 1 for a while but turning back to 0 immediately...

any clues? thank you!

 

 

Two points. First, you appear to have set LVar1Set twice, but you have never set a value for LVar2Set. I assume that's a typing error?

 

Second, just because a gauge records a value in an L:Var doesn't mean it reads it in order to handle the related function. It may not be possible to control the action this way at all.  You could experiment with the order in which you write those three LVars.in case it's critical in the way the gauge is processing.

 

Pete

Link to comment
Share on other sites

The value for the glareshield mounted defrost sliders should max out at '50'.

 

I use two buttons to control those sliders and they work just fine.

 

My C172 MCRO file contains these two definitions:

 

46=L:WindowDefrosterControl1=CYCLIC
47=L:WindowDefrosterControl2=CYCLIC

 

My switch/button assignments in the FSUIPC4.ini file are:

 

36=RA,0,CM16:46,50 ;//LEFT WINDOW DEFROST
37=RA,1,CM16:47,50 ;//RIGHT WINDOW DEFROST

 

I'm not using the "WindowDefrosterControlKnob" L:Var.

 

In most of my "cyclic" operations or those that use the "R", repeat, switch modifier I also create a Lua script

to display the current value(s) for the L:Var as I am changing it. I didn't do that for these two operations but

here is a sample for another A2A product, the P-40, where I display the current "vent" position as I am

changing it:

 

 

The MCRO entry:

17=L:CabinVent=CYCLIC

The INI entry:

48=RA,1,Cx510066C4,x00020001 ;// Trigger lua VENT control & display

The Lua script which is contained in a Lua file for the P-40 along with a dozen

other scripts:

function Vent(offset, val)

  Vent_Set =ipc.readLvar("L:CabinVent")

 

-- Display the vent value for 1 second max

  ipc.display("Vent = "..Vent_Set, 1)

 end

event.offset(0x66C4,"UB","Vent")

 

A similar construct could easily be created for the C172 vents, having the button/switches

modify a couple of the User-defined offsets, as I have done for the P-40, and use the 'event'

trigger to run the Lua script to do the controlling and display.
 

 

    Paul

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.