Jump to content

Recommended Posts

2 hours ago, ark said:

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

Thx,

Al

Al, 

My apologies, this is a Linda function, not a boolean Lua function as I thought. 

Had to get home to verify.

Thanks

 

  • Upvote 1

Share this post


Link to post
Share on other sites
1 minute ago, Henry Street said:

Al, 

My apologies, this is a Linda function, not a boolean Lua function as I thought. 

Had to get home to verify.

Thanks

 

Ah ha, that is why I couldn't make it work! 😊

Thanks for the follow up Henry, appreciate it.

Al

  • Upvote 1

Share this post


Link to post
Share on other sites
18 hours ago, MarkDH said:

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. 

Thanks for your explanations.

The sample code is the one you wrote above:

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

 

Now that I seem to be on the right path, I will try to reach the goal. Thank you very much.


For a sophisticated flight simulation
www.bahrometrix.de

Share this post


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

The sample code is the one you wrote above

  • 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

 

39 minutes ago, Christian Bahr said:

The sample code is the one you wrote above:

I didn't write it, I just tweaked the layout.

  • 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
2 hours ago, Christian Bahr said:

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

  Engine1_Cover_Open ()

else

 Engine1_Cover_Close ()

end

The above code will not run independent of LINDA if that is the intent. I have not used LINDA, but it turns out _t( ) is a toggle function defined in the LINDA library, and it in turn makes use of an array variable defined in LINDA as well. So outside of LINDA, _t( ) is undefined.  I am not a professional programmer, and don't know anything about the aircraft this code refers to, but it seems to me you either have to define your own _t( ) function, or replace the above with something like:

function Engine1_Cover_Toggle ()
    sw_eng1_rpm_cntrl_cover = ipc.readLvar("L:switch engine 1 rpm control cover")
    if sw_eng1_rpm_cntrl_cover == 0 then                                       -- if cover closed
       Engine1_Cover_Open ()                                                          -- open cover
    else
       Engine1_Cover_Close ()                                                         -- if cover was open, close it
    end
 return
end

I am not sure of the big picture here, but if desired you can then write code that checks a FSUIPC parameter and setup FSUIPC accordingly so that an assigned key or button will run the Engine1_Cover_Toggle () function. Each push of the key or button will toggle the position of the engine1 cover.

The same idea holds for the other toggle functions in nd_ec135 that make use of _t( ).

Al

Edited by ark
  • Upvote 1

Share this post


Link to post
Share on other sites

If the above code can not work, then I can test a long time without a result. It's about LINDA not working properly on my system anymore. It comes to a crash. More specifically, to a blue screen. I mentioned that. That's why I want to program a LUA script which works without LINDA but with FSUIPC.

I have tried to execute the code of yours in all earthly and possible combinations by placing it on a button. As a defiance, it does not work. But now I do not want to keep anyone busy with my problem any longer and hope that I can not do any kind of decent button programming. Until then, the corresponding switches in the virtual cockpit are operated with the mouse.

 

regards
Christian

Edited by Christian Bahr

For a sophisticated flight simulation
www.bahrometrix.de

Share this post


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

If the above code can not work, then I can test a long time without a result. It's about LINDA not working properly on my system anymore. It comes to a crash. More specifically, to a blue screen. I mentioned that. That's why I want to program a LUA script which works without LINDA but with FSUIPC.

I have tried to execute the code of yours in all earthly and possible combinations by placing it on a button. As a defiance, it does not work. But now I do not want to keep anyone busy with my problem any longer and hope that I can not do any kind of decent button programming. Until then, the corresponding switches in the virtual cockpit are operated with the mouse.

 

regards
Christian

Christian,

The single function I posted above is just a function definition demonstrating how the original LINDA nd_ec135 code needs to be modified for use with FSUIPC,  it is not a stand alone program in itself. In your case it needs to be incorporated into a larger program along with the other toggle functions in nd_ec135 (also modified), and then some additional selection code is needed to select the particular toggle operation you wish to run with a given key stroke or button. The selection is based on a parameter passed to the program from FSUIPC .  I have taken the time to write this code and will be glad to email the overall program to you with instructions on how to set it up in FSUIPC.  I think once you see how it all fits together with FSUIPC you will find it is not as complicated as it may sound with my rambling description.

Regards,

Al

l

  • Upvote 1

Share this post


Link to post
Share on other sites

Christian -- here is something small you can try.  Copy and past the little test program below into a text editor like Notepad and then save it with some test name like eng1_cover.lua to the sim modules folder. Then assign a key to it using FSUIPC and see if it works with your aircraft to toggle the engine1 cover open and closed. Sometimes you may need to restart the sim after making the key assignment to initialize FSUIPC.

Al

--  *************** function definitions *****************

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

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

function Engine1_Cover_Toggle ()
 sw_eng1_rpm_cntrl_cover = ipc.readLvar("L:switch engine 1 rpm control cover")
    if sw_eng1_rpm_cntrl_cover == 0 then                                       -- if cover closed
       Engine1_Cover_Open ()                                                             -- open cover
    else
       Engine1_Cover_Close ()                                                           -- if cover was open, close it
    end
 return
end
--  ***************** main program *********************

Engine1_Cover_Toggle ()       -- this calls the toggle function defined above when the program is run
return                                               

 

Edited by ark
  • Upvote 1

Share this post


Link to post
Share on other sites

Hello Al.

It works, the last script was successful!!!

Actually, I was almost desperate, but I will not give up that easily. After an infinite number of attempts, a time not measured and the loss of many hairs, there has finally been a really good first step. But one after anonther ...

At the beginning I had reported that it comes to a blue screen when I have called certain P3D menus. The crashes always came in connection with a LUA script in the module folder. Therefore also assume that there must be a connection with LINDA. So, after my assumption, it was either a boisterous Windows 10 update or some other mistake. Now I have just searched for an updated version of FSUIPC and found it. Pete Dowson, the FSUIPC's programmer, has released a new version (V5.132c). And what can I say, the crashes are gone. Pete had apparently previously published a flawed FSUIPC, which in combination with certain combinations with a LINDA LUA script crashed. Well, with the new FSUIPC5.123c the computer is running stable again. With FSUIPC & LUA Script!

The best thing is that with your help I can now finally do a LINDA-independent programming of my switches and buttons. I am so happy and totally on it. The next few days are used intensively to get behind the functionality of the LUA Script.

I can only really thank you for your patience, your knowledge and help. As far as here ..

Now I'm happy again 
:biggrin:


For a sophisticated flight simulation
www.bahrometrix.de

Share this post


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

Hello Al.

It works, the last script was successful!!!

..................

Now I'm happy again 
:biggrin:

Well, Christian,  that is good news indeed!  I've struggled with enough programs to know how frustrating it can be. I am confident I have less hair than you! 

I have to run out now, but I will post later the next step in expanding the above test program.

BTW, you are really up late.

Al

 

Edited by ark
  • Upvote 1

Share this post


Link to post
Share on other sites

Christian,

Here is the next step. Below I have expanded on the test program above so it now includes two toggle functions: Engine1_Cover_Toggle ()  and Engine2_Cover_Toggle () in the same program.

Note the following:

1. The small Open and Close cover function definitions for engine1 precede ( are defined above or before) the definition of the engine1 cover toggle function. That is because the engine1 cover toggle function definition uses the engine1 open and close cover functions. It is always good to define a function before it is used elsewhere.

2. Same idea as above for the three engine 2 cover function definitions ( the open, close and toggle definitions).

3. The main program now includes simple selection logic ( if statement) that will choose between ( call ) either the engine1 or engine2 cover toggle function based on the value of ipcPARAM which is a parameter provided by FSUIPC when the nc_135test program (or whatever name you give to this test program) is called by a key or switch.

4. When you assign a key (or switch) for the engine 1 toggle function as you did before, you will now also enter a 1 in the Parameter field on the FSUIPC key (or switch) assignment tab. This value will be passed to the nc_135test program by FSUIPC as the ipcPARAM value. The main program will then use this value to call the engine 1 toggle function.

5. As above for engine1, when you assign a key (or switch) for the engine 2 cover toggle function, you will enter a 2 in the FSUIPC parameter field. This value will be passed to the nc_135test program (or whatever the program is called) by FSUIPC. The main program will then use this value to call the engine 2 toggle function when the assigned engine2 cover toggle key (or switch) is pressed.

6. Although I used parameter values of 1 and 2 above, you can use any reasonable parameter values you want. Your selection logic then just needs to check for those values.

7. You should be able to save the program below to the modules folder with a name of your choice, assign keys to the engine1 and engine2 cover toggle functions, and then toggle the engine1 and engine2 covers using the two keys or switches you assigned.

8. If you were to further expand the nc_135test program (by modifying the code as needed, eliminating the LINDA  _t() function, etc) to include the six toggle functions in nd_ec135, your main program selection logic would look something like this:

--*******Main Program Selection Logic *****************************************
 if ipcPARAM == 1 then
      Engine1_Cover_Toggle ()            -- function call
      return
  elseif ipcPARAM == 2 then
      Engine2_Cover_Toggle ()            -- function call
      return      
  elseif ipcPARAM == 3 then
      Engine1_RPM_Toggle ()              -- function call
      return
  elseif ipcPARAM == 4 then
      Engine2_RPM_Toggle ()             -- function call
      return
  elseif ipcPARAM == 5 then
      FADEC_Toggle ()                      -- function call                   
      return    
  elseif ipcPARAM == 6 then
      GEN_Toggle ()                        -- function call 
      return         
end
return

You would then assign 6 different keys or switches for the six functions entering the corresponding ipcPARAM values into the FSUIPC Parameter field.

9. There are other 'event driven' approaches to the selection logic idea, but the above is the most straight forward and easiest to understand.

10. The alternative to incorporating the six toggle functions into one program with selection logic is to define 6 separate lua programs like the first small test program you got working. The downside is the number of lua programs can start to grow quite rapidly ( you can only have 256 in the modules folder) and there are more things to keep track of if changes are to be made, etc. I have found it easier to manage things using the 1 program approach when possible.

Well, I hope that gives you a feel for the overall idea.  I'll be glad to answer any questions, and I can also still send you the completely modified nd_ec135 program if you want it. What we have both learned in all this is if you want to run a 'LINDA program' outside the LINDA system, you need to be on the lookout for special functions defined in the LINDA system and modify the code accordingly.

Below is the new slightly expanded test program to try with the two engine toggle cover functions.

Good luck.

Al

 

-- **************nd_ec135 test function definitions *************************************

--  ************** engine1 cover function definitions **********

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

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

function Engine1_Cover_Toggle ()
 sw_eng1_rpm_cntrl_cover = ipc.readLvar("L:switch engine 1 rpm control cover")
    if sw_eng1_rpm_cntrl_cover == 0 then                                       -- if cover closed
       Engine1_Cover_Open ()                                                          -- open cover
    else
       Engine1_Cover_Close ()                                                          -- if cover was open, close it
    end
 return
end

--************** engine2 cover function definitions *********

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

function Engine2_Cover_Close ()
   ipc.writeLvar("L:switch engine 2 rpm control cover", 0)
   return
end

function Engine2_Cover_Toggle ()
 sw_eng2_rpm_cntrl_cover = ipc.readLvar("L:switch engine 2 rpm control cover")
    if sw_eng2_rpm_cntrl_cover == 0 then                                        -- if cover closed
       Engine2_Cover_Open ()                                                    -- open cover
    else
       Engine2_Cover_Close ()
    end
    return
end

-- ******************* main program *******************************

if ipcPARAM == 1 then
      Engine1_Cover_Toggle ()                        -- function call
      return
  elseif ipcPARAM == 2 then                         
      Engine2_Cover_Toggle ()                      -- function call
      return              
end
return

 

 

Edited by ark
  • Upvote 1

Share this post


Link to post
Share on other sites

Christian,

A few additional comments that you may find useful.

First, two things I learned the hard way to be careful about:

1. FSUIPC requires lua program (script) names to be 16 characters or less, not counting the .lua extension. So for example, nd_ec135.lua is an 8 character name and is ok. However, nd_ec135_aircraft.lua is a 17 character name and will not be "seen" by FSUIPC; it will not show up in the FSUIPC drop down key or switch programming lists. This can be very frustrating if you are not aware of the name limitation.

2. You need to be careful when making key or switch assignments to use the correct lua assignment version. For example, if your lua script is nd_ec135 then when making key or switch assignments you usually want to use the 'plain' Lua nd_ec135 from the drop down list (the underscore may not show up which is OK). What you don't want to use is LuaKill nd_ec135, LuaSet nd_ec135, LuaClear nd_ec135, etc. It is easy to make this kind of mistake, I know!

Finally, a couple of programs I have found helpful:

3. Notepad++ is a nice text editor for writing or modifying  Lua programs. Under the language tab you can select Lua and Notepad++ will format and color code things accordingly. Notepad++ is here https://notepad-plus-plus.org/

4. Finally, if a lua program won't run the problem is often a syntax error. One way to check Lua programs for syntax errors is to paste the program into the free LuaEdit 2010 editor and then under the Debug tab you will find Check Syntax. LuaEdit 2010 is here  http://luaedit.sourceforge.net/

I think that's about it.

Al

 

Edited by ark
  • Upvote 1

Share this post


Link to post
Share on other sites

Hello Al.

My sincerest thanks.

Your new script works perfectly. I kept exactly to your instructions and put both functions on two different buttons. Once function 1 is assigned with parameter 1 and once function 2 with parameter 2. If I now press button A, then the left cover is switched through. I press button B, then the right cover is switched through. Just as it was intended. It's perfect!

That would have been my next question. Namely whether one must have a single script for each function, or whether one can have several functions in a script. Your new script answers this question with a clear yes. So if I understand correctly, then you can have infinite many functions in a script, but you have to number the different functions?

 

The one with the maximum character length has already happened yesterday. In the future, I stick to the generally accepted recommendations to keep the filenames on the one hand clear but on the other hand to keep short. With the parameters LuaKill, LuaSet, LuaClear etc I do not know what they are causing, so your recommendation will be followed and I will not "touch" these parameters.

I had previously edited the scripts with Notepad (notepad.exe) from Windows 10, which works very well and without problems. I will follow the tip with the LuaEdit 2010 editor, I've already downloaded the program as a precaution. I'm sure that I'll break it often at the beginning 🙂

Now it starts with the button programming of the Eurocopter EC135. Later, some Airbus functions will be programmed using your script template. I'm really looking forward to it.

My sincerest thanks for your expert knowledge. I was very happy!

best regards
Christian

 

 


For a sophisticated flight simulation
www.bahrometrix.de

Share this post


Link to post
Share on other sites

Hi Christian,

I'm glad I was able to help a bit and that you are happy.  😃

Notepad works fine but the reason I prefer Notepad++ is that it uses different colors to identify lua key commands, comments, etc, which helps prevent syntax errors, at least for me. Certainly use whatever text editor you prefer (don't use a word processor, however).

Note you should have a FSUIPC documentation folder in the sim modules folder with lots of good info on using FSUIPC and Lua coding.

As for grouping functions into one script, I just do what seems to make sense to me based on the script name and the purpose of the functions overall. I would not put lots of functions that don't seem to make sense together or don't have a common overall purpose into one script.

I sent you an email with the complete FSUIPC modified nd_ec135 script based on my limited understanding of what it is supposed to do and what key or switch assignments you may want to make. Let me know if you have any questions.

 

5 hours ago, Christian Bahr said:

Now it starts with the button programming of the Eurocopter EC135. Later, some Airbus functions will be programmed using your script template. I'm really looking forward to it.

Great -- good luck with the programming!

Regards,

Al

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