Jump to content
Sign in to follow this  
Angelo Cosma

Any advanced FSUIPC Users here? .lua Event?

Recommended Posts

Any advanced FSUIPC users here? Getting involved with .lua scripts and setting custom events. Need some direction, if anyone knows what I'm talking about please chime in, I've been reading the supplied documentation for hours.

 

I will go into more detail if anyone knows what I am talking about. 

REALLY appreciate the help thanks!
 

Share this post


Link to post
Share on other sites

Getting involved with .lua scripts and setting custom events. Need some direction,

 

I'm not sure what you mean by setting custom events, but I have some basic Lua script experience in that I've written simple scripts to activate or control various a/c functions like the autopilot, spoilers,  toggle cockpit switches, tune radios, etc. In most cases the idea was to replace having to use the mouse with keys or controller buttons which often is more convenient, at least for me.

 

Al

Share this post


Link to post
Share on other sites

I'm not sure what you mean by setting custom events, but I have some basic Lua script experience in that I've written simple scripts to activate or control various a/c functions like the autopilot, spoilers,  toggle cockpit switches, etc.

 

Al

 

Here you can see the full conversation with Pete Dowson, I am reading the manuals but still comes across as a foreign language to me...

 

http://forum.simflight.com/topic/82747-too-many-inputs-at-the-same-time-possible-issue/

Share this post


Link to post
Share on other sites

Here you can see the full conversation with Pete Dowson, I am reading the manuals but still comes across as a foreign language to me...

 

 

Angelo,

I don’t have any firsthand experience with what you are trying to do or the event.button function, but based on what Pete is saying, here is my best shot at something to try as a start. In the FSUIPC.ini  file you need an Auto section that looks something like this:

 

 [Auto]

1=Throttle_to_Idle_1

2=Throttle_to_Idle_2

3=Throttle_to_Idle_3

4=Throttle_to_Idle_4

 

The above are your 4 Lua script names, one for each engine. Use any 4 different names you like.

Each Lua script would look like the one below, which is just for engine #1. The name of the following script is Throttle_to_Idle_1.lua and this script gets saved in the modules folder.

 

 function ThrottleToIdle_1()-– note this is the name of the function for throttle 1, not the script name

        while true do

          throttle1 = ipc.readSW(0x088c)

      if throttle1 >= 0 then

          break --exit when no more reverse

      end

      ipc.control(65964) -- 65964 = throttle1 incr. Use 65965 for smaller increment

      ipc.sleep(200) 

   end

end

 

event.button(throttle 1 joystick number or letter, throttle 1 button number , 2, "ThrottleToIdle_1")

 

 

In the event.button line above, the throttle 1 joystick number or letter is the “name” of the Saitek throttle quadrant that FSUIPC uses to identify throttle 1 (see the [JoyNames] section of the FSUIPC.ini file)**, the button number is the number of the button at the bottom end of the associated throttle 1 lever that FSUIPC uses to identify that button, the 2 means call the lua function ThrottleToIdle_1 when the button is released.   

 

** EDIT: Or if you go info the FSUIPC Button+ Switches tab with an a/c loaded and activate the appropriate switch at the bottom of the throttle lever travel range, you should see the Joy# and Btn# displayed.

 

What happens is, when FSUIPC sees that the button in the event.button line has been released, it executes the lua function called ThrottleToIdle_1().

 

Now you need three more scripts like the one above, each with changes to account for the different throttles. So, for throttle 2 we would have something like this:

 

 

The name of the following script is Throttle_to_Idle_2.lua and this script gets saved in the modules folder (changes for throttle 2 in red).

 

 function ThrottleToIdle_2()-– this is the name of the function, not the script name

        while true do

          throttle2 = ipc.readSW(0x088c – change this address as needed for throttle 2) 

      if throttle2 >= 0 then

          break --exit when no more reverse

      end

      ipc.control(65969) -- 65969 = throttle2 incr. Use 65970 for smaller increment

      ipc.sleep(200) 

   end

end

 

event.button(now use throttle 2 joystick number or letter, use throttle 2 button number , 2, "ThrottleToIdle_2")

 

You now need to define two more scripts for throttles 3 and 4 making similar changes as needed.

 

Hope this helps,

Al

Share this post


Link to post
Share on other sites

Angelo,

I don’t have any firsthand experience with what you are trying to do or the event.button function, but based on what Pete is saying, here is my best shot at something to try as a start. In the FSUIPC.ini  file you need an Auto section that looks something like this:

 

 [Auto]

1=Throttle_to_Idle_1

2=Throttle_to_Idle_2

3=Throttle_to_Idle_3

4=Throttle_to_Idle_4

 

The above are your 4 Lua script names, one for each engine. Use any 4 different names you like.

Each Lua script would look like the one below, which is just for engine #1. The name of the following script is Throttle_to_Idle_1.lua and this script gets saved in the modules folder.

 

 function ThrottleToIdle_1()-– note this is the name of the function for throttle 1, not the script name

        while true do

          throttle1 = ipc.readSW(0x088c)

      if throttle1 >= 0 then

          break --exit when no more reverse

      end

      ipc.control(65964) -- 65964 = throttle1 incr. Use 65965 for smaller increment

      ipc.sleep(200) 

   end

end

 

event.button(throttle 1 joystick number or letter, throttle 1 button number , 2, "ThrottleToIdle_1")

 

 

In the event.button line above, the throttle 1 joystick number or letter is the “name” of the Saitek throttle quadrant that FSUIPC uses to identify throttle 1 (see the [JoyNames] section of the FSUIPC.ini file), the button number is the number of the button at the bottom end of the associated throttle 1 lever that FSUIPC uses to identify that button, the 2 means call the lua function ThrottleToIdle_1 when the button is released.

 

What happens is, when FSUIPC sees that the button in the event.button line has been released, it executes the lua function called ThrottleToIdle_1().

 

Now you need three more scripts like the one above, each with changes to account for the different throttles. So, for throttle 2 we would have something like this:

 

 

The name of the following script is Throttle_to_Idle_2.lua and this script gets saved in the modules folder (changes for throttle 2 in red).

 

 function ThrottleToIdle_2()-– this is the name of the function, not the script name

        while true do

          throttle2 = ipc.readSW(0x088c – change this address as needed for throttle 2) 

      if throttle2 >= 0 then

          break --exit when no more reverse

      end

      ipc.control(65969) -- 65969 = throttle2 incr. Use 65970 for smaller increment

      ipc.sleep(200) 

   end

end

 

event.button(throttle2 joystick number or letter, throttle2 button number , 2, "ThrottleToIdle_2")

 

You now need to define two more scripts for throttles 3 and 4 making similar changes as needed.

 

Hope this helps,

Al

 

 

Thank you so much! So I found the joy id and button number does this look right?
 
function ThrottleToIdle()
           while true do 
               throttle3 = ipc.readSW(0x09BC) 
         if throttle3 >= 0 then   
               break --exit when no more reverse 
         end 
         ipc.control(65974)--65974 = throttle3 incr. Use 65965 for smaller increment 
         ipc.sleep(300) -- adjust for speed of increase. 10mSecs = 100 per second
     end
end
 
event.button(0, 8 , 2, "ThrottleToIdle")
 
 
So the bold, Joy ID was Joy Zero and Button Eight, IDK what the 2 is in refernce to. So I need to add the those 4 lines in the Auto in the FSUIPC .ini and it should all work in theory?

Share this post


Link to post
Share on other sites

function ThrottleToIdle()

while true do

throttle3 = ipc.readSW(0x09BC)

if throttle3 >= 0 then

break --exit when no more reverse

end

ipc.control(65974)--65974 = throttle3 incr. Use 65965 for smaller increment

ipc.sleep(300) -- adjust for speed of increase. 10mSecs = 100 per second

end

end

 

event.button(0, 8 , 2, "ThrottleToIdle")

 

Angelo,

Each of the 4 scripts should have a different name, and each function in those scripts should have a different name. So in the event.button line, you can't use "ThrottleToIdle" 4 times for the 4 scripts.You need "ThrottleToIdle_1, ThrottleToIdle_2, etc, for the function names in the 4 different scripts. As for the throttle and button names that FSUIPC uses, I can't tell "from here".  For the throttle name and button numbers, if you go info the FSUIPC Button+ Switches tab with an a/c loaded and activate the appropriate switch at the bottom of the throttle lever travel range, you should see the Joy# and Btn# displayed.

 

Al

Share this post


Link to post
Share on other sites

Angelo,

Each of the 4 scripts should have a different name, and each function in those scripts should have a different name. So in the event.button line, you can't use "ThrottleToIdle" 4 times for the 4 scripts.You need "ThrottleToIdle_1, ThrottleToIdle_2, etc, for the function names in the 4 different scripts. As for the throttle and button names that FSUIPC uses, I can't tell "from here".  For the throttle name and button numbers, if you go info the FSUIPC Button+ Switches tab with an a/c loaded and activate the appropriate switch at the bottom of the throttle lever travel range, you should see the Joy# and Btn# displayed.

 

Al

Okay understood, and from FSUIPC the button for engine 3 I checked was Joy 0 and Button number 8.

 

So in the .lua simply putting 0 and 8 there is good? What is that number 2?

This is for engine 3 and I added the auto section to the fsuipc.ini

 

function ThrottleToIdle_3()
while true do 
throttle3 = ipc.readSW(0x09BC) 
if throttle3 >= 0 then   
break --exit when no more reverse 
end 
ipc.control(65974)--65974 = throttle3 incr. Use 65965 for smaller increment 
ipc.sleep(300) -- adjust for speed of increase. 10mSecs = 100 per second
     end
end
 
event.button(throttle2 0, 8 , 2, "ThrottleToIdle_3")

Share this post


Link to post
Share on other sites

What is that number 2?

 

The 2 means to call and activate the ThrottleToIdle_n function when the button is released. Using a 1 (or blank) there would mean activate the ThrottleToIdle_n function when the button is Pressed, and 3 would mean activate the ThrottleToIdle_n function when the button is Pressed or Released. See the event.button description in the FSUIPC documentation called FSUIPC Lua Library.pdf.

 

At this point I would suggest you write one script and see if you can get it working as you would like for that engine. Once that's done, you should be in good shape to get the other three working.

 

Al

Share this post


Link to post
Share on other sites

Okay gonna try this quick with number 3 engine and report back in a couple minutes.


Okay nothing is happening when the button is released. 


Okay this is in the FSUIPC.ini:

 

[Auto]
1=Throttle_to_Idle_1
2=Throttle_to_Idle_2
3=Throttle_to_Idle_3
4=Throttle_to_Idle_4
 
I also noticed this section (.LUA FILES)
 
[LuaFiles]
1=Idle1
2=Idle2
3=fsiaes1
4=fsiaes2
5=fsiaesns
6=fsiaesnsclr
7=testfsi
8=Idle3
9=Idle4
 
The newly created one is not listed.
 
The one we are testing is titled:
 
Throttle_to_Idle_3.lua

Share this post


Link to post
Share on other sites

Okay nothing is happening when the button is released

 

Angelo,

I see one problem -- my fault, sorry. Lua script names can't have more than 16 characters, so names like Throttle_to_Idle_3 are too long. Change the name to something like Throttle_Idle_3.lua, or something else you like.

 

Al

Share this post


Link to post
Share on other sites

Print the lua script code here, and also part of the modules folder that shows the script name.

Al

 

Heres a pic

 

Untitled.jpg

 

Its not keeping the formatting for whatever reason but it looks like your example in note pad.

 

 

function ThrottleToIdle_3()
while true do 
throttle3 = ipc.readSW(0x09BC) 
if throttle3 >= 0 then   
break --exit when no more reverse 
end 
ipc.control(65974)--65974 = throttle3 incr. Use 65965 for smaller increment 
ipc.sleep(300) -- adjust for speed of increase. 10mSecs = 100 per second
     end
end
 
event.button(throttle2 0, 8 , 2, "ThrottleToIdle_3")

Does FSUIPC need to refresh somehow to see the newly added lua or sim reboot?

 

BIG EDIT: Okay I found a typo in the lua, I had engine 2 in the joy button line for throttle 3. I tried throttle 2 in sim and it worked. It idled way too quickly tho so I need to adjust ipc sleep? I want to extend the idle time by double maybe a bit more.

Share this post


Link to post
Share on other sites

function ThrottleToIdle_3()
while true do 
throttle3 = ipc.readSW(0x09BC) 
if throttle3 >= 0 then   
break --exit when no more reverse 
end 
ipc.control(65974)--65974 = throttle3 incr. Use 65965 for smaller increment 
ipc.sleep(300) -- adjust for speed of increase. 10mSecs = 100 per second
     end
end
 
event.button(throttle2 0, 8 , 2, "ThrottleToIdle_3")

Does FSUIPC need to refresh somehow to see the newly added lua or sim reboot?

Take throttle2 out of the event.button line. It should just be event.button ( 0, 8 , 2, "ThrottleToIdle_3") assuming the "0" is the number (name) of the Saitek throttle quadrant.

 

Does FSUIPC need to refresh somehow to see the newly added lua or sim reboot?  Sometimes it seems so. You can try using the Reload all Buttons button under the FSUIPC Buttons + Switches tab, but if all else fails restart FSX to be sure.

Al

Share this post


Link to post
Share on other sites

Okay Reloaded all buttons, Rebooted PC, and nothing :-/

 

If hypothetically I was to assign this lua as a button in fsuipc, it doesnt appear in the drop down with the rest of the others. Any reason why its not showing in the list even?

 

 

1_Untitled.jpg


Take throttle2 out of the event.button line. It should just be event.button ( 0, 8 , 2, "ThrottleToIdle_3") assuming the "0" is the number (name) of the Saitek throttle quadrant.

 

Does FSUIPC need to refresh somehow to see the newly added lua or sim reboot?  Sometimes it seems so. You can try using the Reload all Buttons button under the FSUIPC Buttons + Switches tab, but if all else fails restart FSX to be sure.

Al

Share this post


Link to post
Share on other sites

Did you change the name of the script to use 16 characters or less as I mentioned above?

Al

Share this post


Link to post
Share on other sites

Did you change the name of the script to use 16 characters or less as I mentioned above?

Al

 

Now I did, editing the two long named ones now. Do I also edit the names in the Auto Section of the fsuipc.ini to match?

Okay they are showing in FSUIPC now, and I reloaded all buttons. Still not doing anything the throttle though. I even assigned it in buttons to see if it did something when button was released and still nothing. So maybe theres an issue with the code in the script?

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