Jump to content

Recommended Posts

Hello.

In all likelihood I am not the first Simmer to ask this question, please be lenient with me. I would like to read a LUA script, in which functions for an aircraft are stored, in FSUIPC and then access these functions by means of button assignment. If I copy this script into the Module folder of the P3D, it will appear in FSUIPC, but I can not access the functions:

p3dv4_fsuipc_lua_script_ec135.jpg
P3D-Modules folder with ec135.lua script

 

p3dv4_fsuipc_ini.jpg
FSUIPC.ini LUA-Script entry

 

p3dv4_fsuipc_button_menu.jpg
Button-Menu in FSUIPC

 

My question: must be in the module folder next to the LUA script more LUA files? So I have to download LUA from somewhere and do a "LUA installation"?

So far, I'm not getting really smart about the whole thing. I searched the Internet all over, read English-language pages as well as German-language pages. But I can not get any further.

I added an example of a created LUA script: http://bahrometrix.de/FSX_P3D/share/nd_ec135.zip
The Script was formerly designed for LINDA. But I do not use LINDA anymore.


For a sophisticated flight simulation
www.bahrometrix.de

Share this post


Link to post
Share on other sites

Christian,

Things are looking correct in your FSUIPC. 

I am thinking there is an issue with your LUA script formatting. Scripts direct from LINDA will not work directly in FSUIPC.

If you want to combine many functions in one script, here is a good example: npc4fsx&p3d.zip by Al Klayton. Al has many scripts here at Avsim Library. See how Al use FSUIPC to autostart the script?

Many times, it is easier to create many scriptlets. Here is an example I created: https://uchisworld.wordpress.com/2016/02/06/this-game-of-ghosts/

Good luck with your scripting adventure. FSUIPC and LUA are very powerful.

Edited by Henry Street
  • Upvote 1

Share this post


Link to post
Share on other sites
5 hours ago, Christian Bahr said:

I added an example of a created LUA script: http://bahrometrix.de/FSX_P3D/share/nd_ec135.zip
The Script was formerly designed for LINDA. But I do not use LINDA anymore.

Christian ,

I looked at the ec135 script. As written (in Linda style) it will not run as a 'simple' Lua script. I will be glad to try and rewrite it so you can use the rewrite as an model for your other scripts, but I need to know what functions you want to activate with keys or buttons. Is it just the toggle functions in the original script that you want to assign buttons or keys too?

Al

Edited by ark
  • Upvote 1

Share this post


Link to post
Share on other sites

Hello Henry,

many thanks for your response. Something similar I had already thought that the LUA script for FSIPC must have a different formatting. The format for LINDA LUA Script is:

Sample Code ND Eurocopter EC135

-- ## Engine Cover Control ###############

function Engine1_Cover_Open ()
   ipc.writeLvar("L:switch engine 1 rpm control cover", 1)
end

function Engine1_Cover_Close ()
   ipc.writeLvar("L:switch engine 1 rpm control cover", 0)
end

function Engine1_Cover_Toggle ()
	if _t("switch engine 1 rpm control cover", 1) then
       Engine1_Cover_Open ()
	else
       Engine1_Cover_Close ()
	end
end

 

I have downloaded the zip archive you mentioned and I will take a look at the content. Still a question :Which characters have to be changed in order for the LUA Script FSUIPC to be compliant?

By the way: the link from you ends on an unknown website


For a sophisticated flight simulation
www.bahrometrix.de

Share this post


Link to post
Share on other sites
1 hour ago, ark said:

Christian ,

I looked at the ec135 script. As written (in Linda style) it will not run as a 'simple' Lua script. I will be glad to try and rewrite it so you can use the rewrite as an model for your other scripts, but I need to know what functions you want to activate with keys or buttons. Is it just the toggle functions in the original script that you want to assign buttons or keys too?

Al

 Hello AI.

Thank you for your very friendly offer. To be honest, a simple example script would be enough for me to start with. For me, the information that there are different formats between a LINDA LUA script and an FSUIPC LUA script is completely new. If I had known that before, I would probably already be one step ahead.

I had just downloaded a sample script from Avsim Lib (npc4fsx & p3d.zip). I suppose that will help me a bit. But I do not really know yet, how far I will get with the script example. So the funtions from the ec135 script, because I have to see exactly what keys are. Will post this later here.

 


For a sophisticated flight simulation
www.bahrometrix.de

Share this post


Link to post
Share on other sites

Christian,

PM me your email address and I will send you the modified script and some instructions on how to set it up using FSUIPC. I have no way to test the script so it may take a few tries to debug it.  🙁

1 hour ago, Christian Bahr said:

I had just downloaded a sample script from Avsim Lib (npc4fsx & p3d.zip). I suppose that will help me a bit. But I do not really know yet, how far I will get with the script example

The npc4fsx&p3d script is a fairly complex script ( at least for me ) that uses flags for function selection. I think the script I will send you, which uses FSUIPC parameter values for function selection, will be a more useful model for modifying your other scripts.

Al

Edited by ark
  • Upvote 1

Share this post


Link to post
Share on other sites
1 hour ago, Christian Bahr said:

Which characters have to be changed in order for the LUA Script FSUIPC to be compliant?

This is not an issue of formatting, LINDA uses the FSUIPC Lua engine so FSUIPC will understand anything LINDA understands. In the example you posted, I would say you need to write it like this:

-- ## Engine Cover Control ###############

local function Engine1_Cover_Open ()
   ipc.writeLvar("L:switch engine 1 rpm control cover", 1)
end

local function Engine1_Cover_Close ()
   ipc.writeLvar("L:switch engine 1 rpm control cover", 0)
end

if _t("switch engine 1 rpm control cover", 1) then
    Engine1_Cover_Open ()
else
   Engine1_Cover_Close ()
end

You will see I have removed the function header and 'end' statement from the main function. You should think of a Lua script as a complete program rather than as a callable function as in LINDA. In other words, the script starts executing from the top when invoked from a keystroke. In this case it defines a couple of helper functions and then executes the body of what was previously the Engine1_Cover_Toggle() function. Style dictates that you should also put the word 'local' in front of the function definitions to emphasise that they are helper for this program only, although it will work without that.

I think there is a way for FSUIPC to address individual functions in a file but it's clunky and has something to do with passing a numeric argument. personally I would use LINDA, it makes things so much easier.

Edited by MarkDH
  • Upvote 1

MarkH

gGzCVFp.jpg
Core i7-7700K / 32Gb DDR4 / Gigabyte GTX1070 / 1080p x 3 x weird / Win7 64 Pro

Share this post


Link to post
Share on other sites
34 minutes ago, MarkDH said:

if _t("switch engine 1 rpm control cover", 1) then

Engine1_Cover_Open ()

else Engine1_Cover_Close ()

end

Mark,

What does the _t operator in the above mean or do?

Thx,

Al

  • Upvote 1

Share this post


Link to post
Share on other sites
18 minutes ago, ark said:

Mark,

What does the _t operator in the above mean or do?

Thx,

Al

t stands for "true" 

  • Upvote 1

Share this post


Link to post
Share on other sites

Hello.

Can we agree that we will go through this step by step so that we can find possible sources of error gradually? For a real beginner like me that would be a great help.

2 hours ago, ark said:

PM me your email address and I will send you the modified script and some instructions on how to set it up using FSUIPC. I have no way to test the script so it may take a few tries to debug it🙁

 

I am happy to send you my e-mail. But would not it be much better we would discuss this topic openly here and all other interested parties can read along here and participate in a possible solution?

Mark, thank you first for your help. I copied the section into the script purely. But unfortunately that does not work. It was almost to be expected. How do I have to set this in FSUIPC? The switch is normal Botton on Coli-Hat:

p3dv4_lua_script_test1.jpg

 

 

1 hour ago, Henry Street said:

t stands for "true" 

Does that mean I have to replace "t" with "true"?

 

 


For a sophisticated flight simulation
www.bahrometrix.de

Share this post


Link to post
Share on other sites
17 minutes ago, Henry Street said:

t stands for "true" 

So then the underscore in front of the "t" makes it 'not true'?

Thx,

Al

  • Upvote 1

Share this post


Link to post
Share on other sites
37 minutes ago, Christian Bahr said:

Mark, thank you first for your help. I copied the section into the script purely. But unfortunately that does not work. It was almost to be expected. How do I have to set this in FSUIPC? The switch is normal Botton on Coli-Hat:

I was assuming you were binding the button to 'Lua <name>', not 'LuaValue <name>'. If your Lua file is called 'EngineCoverToggle.lua, you should bind your button to the action labelled 'Lua EngineCoverToggle'.

  • Upvote 1

MarkH

gGzCVFp.jpg
Core i7-7700K / 32Gb DDR4 / Gigabyte GTX1070 / 1080p x 3 x weird / Win7 64 Pro

Share this post


Link to post
Share on other sites
16 minutes ago, Christian Bahr said:

I am happy to send you my e-mail. But would not it be much better we would discuss this topic openly here and all other interested parties can read along here and participate in a possible solution?

I am not familiar with LINDA, and am not sure what functions in the script you actually want to assign keys or button too so my  intent was to have you look at some things and possibly provide feedback before posting a lot of stuff here that may not be helpful.  It is also not convenient to post FSUIPC screen shots here. You are certainly welcome to post here anything I send you that you think may be generally helpful to the overall discussion.

Al

 

 

  • Upvote 1

Share this post


Link to post
Share on other sites
1 hour ago, MarkDH said:

I was assuming you were binding the button to 'Lua <name>', not 'LuaValue <name>'. If your Lua file is called 'EngineCoverToggle.lua, you should bind your button to the action labelled 'Lua EngineCoverToggle'.

Hello Mark.

I have tried this now, unfortunately it does not work. Best I describe briefly the procedure.

1. An empty text file is created in the Module folder. I rename them -> ec135.lua
2. I copy the text into the empty text file and save it
3. Start the P3D, go to FSUIPC and select the button
4. In the Functions drop-down menu I go to LUA and select the LUA script


But nothing happens when I press the button with the LUA script. What do I have to enter under parameter: 0/1?

p3dv4_lua_script_test2_neu.jpg


 

Edited by Christian Bahr

For a sophisticated flight simulation
www.bahrometrix.de

Share this post


Link to post
Share on other sites
15 minutes ago, Christian Bahr said:

I have tried this now, unfortunately it does not work. Best I describe briefly the procedure.

As far as I can tell the procedure you describe is correct, although it will depend on what text you have put in your file (ec135.lua). I don't think I can help any further as I don't know anything about this example code or this particular aircraft.

  • Upvote 1

MarkH

gGzCVFp.jpg
Core i7-7700K / 32Gb DDR4 / Gigabyte GTX1070 / 1080p x 3 x weird / Win7 64 Pro

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...