Jump to content
Sign in to follow this  
stefwei

How to assign buttons to Lua files?

Recommended Posts

I'm new to Linda and followed the manual so far to make my first steps.

It's said that one may delete any Lua related entries in FSUIPC and assign buttons to Lua files later. But I did not find how to do this.

I tried to create a function in the User library: ipc.runlua("MyPath") and assigned it to a button but that didn't work.

Thanks for any help to understand how this is done.

Share this post


Link to post
Share on other sites

Hi Stefwei

Welcome to the LINDA community. I have not done what you suggest with LINDA. In most cases you would create a LUA function with its own code in LINDA and call it directly. However, the ipc.runlua command should work if placed in the correct structure.

There are 2 recommended locations for placing user written code: lib-users.lua (/modules/linda/libs/) for global use across all aircraft or user.lua for each specific aircraft (/modules/linda/aircrafts/{your aircraft}/). You create a uniquely named function (MyRunCode) containing your required LUA code. For example,

function MyRunCode()

ipc.runlua("mycode")

end

The path should be either the full address or start within the /modules/ directory). After editing your user.lua code (using LINDA Editor), save it and then click on Restart LUA Engine to load the code into LINDA's runtime structure. The LINDA Editor will check for any syntax errors before saving.


Andrew Gransden

Scotland, UK

LINDA Support/Developer - VATSIM and BAVirtual - Airbus Flyer

i7 1TB SSD GTX980 - FSX/P3D - Aerosoft Airbus A318/A319/A320/A321 - FS2Crew

Share this post


Link to post
Share on other sites

Hi,

that is what I tried but it doesn't work.

I added the following function to the FSX lib-users.lua file :

function ColdAndDark()
ipc.runlua("MyP3DPath\Modules\GFpower.lua")
end

and assigned a button to the function, reloaded Linda. No success. Then I tried it with my King Air airplane. It did not work either. I even changed the location of the file to see what happens. It does not work.

Share this post


Link to post
Share on other sites

Find the LUA programming document in /modules/fsuipc documents/ and check the syntax for the command. I am not sure whether the .lua is required and assume that modules is the root directory. I would need to try coding it myself to give you more help. 


Andrew Gransden

Scotland, UK

LINDA Support/Developer - VATSIM and BAVirtual - Airbus Flyer

i7 1TB SSD GTX980 - FSX/P3D - Aerosoft Airbus A318/A319/A320/A321 - FS2Crew

Share this post


Link to post
Share on other sites

Hi Stefwei

I have had a chance to investigate you problem. In the /modules/FSUIPC Documents directory you will find a zipped folder called 'Example LUA plugins'. This gives a range of examples of working plugins. The Plugins open within their own thread so cannot call any LINDA defined functions. There is also a useful document FSUIPC Lua Plug-ins.pdf.

For my test, I copied the plugin display vals.lua into the /modules directory. I then created a function in the lib-user.lua file:

  • function TestPlugins()
  • ipc.runlua('display vals')
  • end

Note: Right-clicking on the function name allows you to test the function without assigning to any button.

It is important that the plugin sits in the /modules directory and no .lua extension is required within the ipc.runlua command. It is also important that the lua plugin does something visible as no error reporting occurs for debugging purposes.


Andrew Gransden

Scotland, UK

LINDA Support/Developer - VATSIM and BAVirtual - Airbus Flyer

i7 1TB SSD GTX980 - FSX/P3D - Aerosoft Airbus A318/A319/A320/A321 - FS2Crew

Share this post


Link to post
Share on other sites

Hi Andrew,

You got it. I proceeded right as you suggested and everything works now.

I have two remarks:

  1. I already tried different locations of the .lua file and different combinations of everything. But when I tried out every individual change it did not work. I think that there may be some trouble to get the Lua engine entirely reloaded every time I change my lua file and save it (do you recommend an external editor like Notepad++ or do you work with the Linda Editor? ). Usually I click on "Reload Lua Engine" and wait a couple of seconds and then proceed.
  2. I strongly recommend to insert this kind of information in the manual to guide the beginner to put his LuaFiles in the \Modules folder and not to keep the .lua extension in the script. These are two major informations I was missing.

The manual is a very neat piece better written than most of these manuals which just tell the user to do what everybody may already have the intuition for. The manual helped me a lot but there is a kind of conceptual brake in the middle because it leaves the path where the upcoming user like me is going to use LINDA to emphasize tracing and very MCP related things. This is surely very useful and requested by lots of MCP users. So, that's all right.

I will come back with other questions as I will surely continue my exploration. But I will open another thread then.

Thanks again,

Stefan

Share this post


Link to post
Share on other sites

Hi Stefen

I am pleased you have things working. It took me a few false attempts to get things working. I prefer using the LINDA editor for all LUA work as it includes an automatic syntax checker. After savings any changes, clicking on Reload LUA Engine performs a full reboot of the LINDA LUA code ensuring all core code, libraries and modules are reloaded and initialised.

The manual was written some years ago and unfortunately we do not have the source file. Most users don't explore LUA or having any knowledge of programming as you have. It was also written as a time when the MCP was the key hardware supported and joysticks were limited in their support.

Enjoy using LINDA and I always welcome new insights and suggestions.

 


Andrew Gransden

Scotland, UK

LINDA Support/Developer - VATSIM and BAVirtual - Airbus Flyer

i7 1TB SSD GTX980 - FSX/P3D - Aerosoft Airbus A318/A319/A320/A321 - FS2Crew

Share this post


Link to post
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
Sign in to follow this  

  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...