Jump to content
The simFlight Network Forums

Recommended Posts

Posted

Dear friends, hello. I am very sorry to bother you with such a small issue, maybe you explained this issue a hundred times, but I am very new to LUA programming, and I need some help from you to make me start moving.

My Virtual Airline recorder application gets data from sim by the help of FSUIPC client (Coded with .NET), but unfortunately FSLabs Airbus aircraft does not produce any data about flaps. What I want to do is to create a LUA file, which continously checks one of the LVARS (I already know the name of LVAR and the values it gets according to the flap lever position), then I want this LUA to assign a value to our FSUIPC OFFSET used for flaps (0x0BDC).

-------------------------------------------------------------------------------------

Here is the LVAR info :

VC_PED_FLAP_LEVER

0=UP
110=Flap1
210=Flap2
310=Flap3
410=Flap4

And here is the code that I tried to make :

--------------------------------------------------------------------------------------

flappos=ipc.readLVar("L:VC_PED_FLAP_LEVER")

if flappos == nil then
    -- if there is no LVAR like this do nothing because the pilot is not flying an FSLabs Airbus
else
    if flappos == 0 then
        -- if there is an LVAR like this and if it is 0 then do nothing because FSUIPC already returns 0
    else
        -- if there is an LVAR with this name and if its value is not 0 then lets begin

        if flappos >= 100 and flappos < 200 then
            ipc.writeUD(0x0BDC, 4096)
        end

        if flappos >= 200 and flappos < 300 then
            ipc.writeUD(0x0BDC, 8192)
        end

        if flappos >= 300 and flappos < 400 then
            ipc.writeUD(0x0BDC, 12288)
        end

        if flappos >= 400 then
            ipc.writeUD(0x0BDC, 16384)
        end
    end
end

--------------------------------------------------------------------------------------

Since I dont have FSLabs aircraft in my inventory, I will create a LUA file and send it someone to check, but I want to make sure if the code is fine. This is my first time in LUA coding, I will appreciate your guidings.

My first question is, will that code run automatically as long as the sim runs if I place ...

----------------------------------------------------------------------------------------------

[AUTO]

1=Lua nameoftheLUAfile

----------------------------------------------------------------------------------------------

as the last line in FSUIPC.ini ?

Second question is... Is the code OK?

Posted

That lua script will only run through once and then terminate. You need to be constantly checking the LVAR in a loop. Or, better still use event.LVAR to execute your function when the value of the flaps changes.  Something like this (I'm not a LUA expert).

function setFlaps(varname, flappos)
	if flappos == nil then
    	-- if there is no LVAR like this do nothing because the pilot is not flying an FSLabs Airbus
	else
   		if flappos == 0 then
    	    -- if there is an LVAR like this and if it is 0 then do nothing because FSUIPC already returns 0
    	else
        	-- if there is an LVAR with this name and if its value is not 0 then lets begin

     	    if flappos >= 100 and flappos < 200 then
            	ipc.writeUD(0x0BDC, 4096)
       	    end

        	if flappos >= 200 and flappos < 300 then
            	ipc.writeUD(0x0BDC, 8192)
        	end

        	if flappos >= 300 and flappos < 400 then
            	ipc.writeUD(0x0BDC, 12288)
        	end

        	if flappos >= 400 then
            	ipc.writeUD(0x0BDC, 16384)
        	end
    	end
    end
end

event.Lvar("L:VC_PED_FLAP_LEVER",500,"setFlaps")

 

Alternatively, you could use the LVAR facility in my Client DLL and build it into the application.

double flapStatus = FSUIPCConnection.ReadLVar("L:VC_PED_FLAP_LEVER");

 

Paul

Posted

Ahh Paul, I really didn't know I could use LVAR facility with your marvellous dll. (How did I not see that before? 🙂Sir, thank you very much, for your help and for creating such a great dll. I will do lots of things with this facility. Thanks again.

  • Like 1
  • Thanks 1
  • 2 years later...
Posted
On 10/31/2018 at 9:11 PM, Paul Henty said:

Alternatively, you could use the LVAR facility in my Client DLL and build it into the application.

double flapStatus = FSUIPCConnection.ReadLVar("L:VC_PED_FLAP_LEVER");

Paul, I couldn't use this ReadLVar facility on my app. I am on Visual Basic and I use these codes to get data from the sim...

OpenFSUIPC()

Dim groundspeed As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)(&H2B4)

gloGS = (groundspeed.Value * 1.9438445) / 65536.0

...

 

What is the required code for VB to get LVAR value?

  • 2 weeks later...

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.