Most of the commonly reported issues and questions are answered in the Frequently Asked Questions (FAQ) option under the Support menu of this website.
*** PLEASE NOTE ***
Your forum account is not the same as the account used in the shop. They are completely separate accounts.
1st December: A new version of the GoFlight Interface Tool for MSFS is now available.
12th November: A new version of the GoFlight Interface Tool for X-Plane is now available.
6th June: A new version of Virtual Flight Sim Hardware is now available (huge update)
21st November: A new version of the GoFlight Interface Tool for FSX/FSXSE/P3D is now available.

LUA Questions

Im trying to convert a script written for another interface tool, which looks quite similar in syntax to LUA.

Ive managed to convert a sample piece of code to work in GIT.
From what I can see, Ill need a separate lua text file for every different 'Bespoke Event' I wish to write. As some of the code will be common, Ive tried to see if I can write these as functions, and store them in a FUNCTION definition file, and call them via a 'require' command.

This seems to work, however I cant seem to work out what path I need to include for it to use the same directory of the aircraft's LUA file in the GIT My Documents path.
Is there a GIT/LUA env I can use as a shortcut to this path?

From the debug code I worked out it will try to seach for a LUA dir within the P3D sim directory, so for the time being Ive placed it there.

Is it possible to pass a value to the LUA BespokeScript via the 'Button Action->Custom' option?
If I can do this, then I can pass a value to the same LUA BespokeScript, and depending on the value passed to the script, it can call different functions.
This would mean I could place more LUA actions within the one LUA script, rather than having a single script for each and every action.

This is what my function file looks like:

-- # LUA Master functions for AS Airbus
function AB_OVH_APU_BLEED_off()
setlvar("AB_OVH_PNEUBLEEDAPU",0)
setlvar("SmallOverheadPushButtons",1)
end

function AB_OVH_APU_START_off()
setlvar("AB_OVH_APU_MASTER",0)
setlvar("SmallOverheadPushButtons",1)
end

function AB_OVH_APU_MASTER_on()
setlvar("AB_OVH_APU_MASTER",1)
setlvar("SmallOverheadPushButtons",1)
end

function AB_OVH_APU_MASTER_off()
setlvar("AB_OVH_APU_MASTER",1)
setlvar("SmallOverheadPushButtons",1)
AB_OVH_APU_BLEED_off()
AB_OVH_APU_START_off()
end





And this is what the APU LUA script looks like:

require("ASA_MASTER");
if (getlvar("AB_OVH_APU_MASTER") == 0) then
AB_OVH_APU_MASTER_on()
else
AB_OVH_APU_MASTER_off()
end


Regards
David
Regards
David

Comments

  • edited July 2018
    Hi David,

    Have you tried something along the lines of "C:\Documents\GoFlight Interface Tool\LUA\aircraft_name". E.g. C:\Documents\GoFlight Interface Tool\LUA\beech_baron_58.

    You cannot pass values into Lua scripts. You can however read the state of the button/switch or rotary that started the Lua script using getlastinput(). I can add the facility to the next release of GIT if you think its useful?

    Best wishes
    Steve
  • Hi Steve

    The reason I was thinking about being able to pass a value via the LUA script was to try to minimize the number of individual LUA scripts, as at the moment I need to write a separate LUA file for every GF button/switch that I want to trigger LUA.

    If I was able to pass a value I could set this value to a different number for each of the GF buttons, and call the same LUA script, I could deduct which button or switch or rotary called the LUA script and then run the appropriate function.

    Another way to reduce the number of LUA scripts would be if it was possible to call a specific FUNCTION within the LUA script. Perhaps, if a function was defined as

    function GIT_xxxxxxx

    in the LUA scripts, and those functions with the named prefix of GIT_ would appear in the dropdown of Bespoke events I could call for a given button. That way I wouldn't need to pass a value to the LUA script, and I could have all my functionality in just a few LUA files.

    Once question I do have, is, are the scripts, opened, and read, kept in memory, or does the file have to be located, read, executed, and the file closed every time a LUA script is called? If its loaded every time its called, I am then concerned if the size of my LUA 'function' script that is loaded via the REQUIRED LUA command, would add delay everytime its called/used.


    All of this is because its easy to write the LUA code in a text editor, and I dont need P3D open.
    Whilst I do like the standard GIT Bespoke editor, it does mean that I have to have P3D open running the aircraft to be able to do any coding. As I have limited time at my P3D pc, it does make writing bespoke code slower for me.


    Regards
    David
    Regards
    David
Sign In or Register to comment.