Jump to content
The simFlight Network Forums

SOLVED: Need help with a couple LUA Questions


Recommended Posts

Questions answered with a more thorough read of the lua doc's, study of other peoples scripts, and the help of another user via a different post.

I've only attempted one other piece of programming with LUA so I'm still trying to figure things out and doing a great deal of head scratching. I'm writing a script to handle several of the switch functions on my Carenado King Air C90. Among the things I'm challenged by: I need to better understand how to read the state of an existing function; And, I need to get a better idea of how to capture switch actions using the logging function.

Here are a couple examples wher I am trying to get physical switches on my sim pit panel:

In this code which resides in with other code I am changing the state of the Transfer pump switch. However, under certain circumstances the code executes when the physical switch and the sim function are already in sync and it causes the sim switch to cycle or jump out of and back into the correct state. Can I use one of the "ipc.read_____" commands to determine the transfer pumps current state so I can bypass these lines of code when not needed?


-- TRANSFER PUMPS
if ipc.testbutton(3,3) == true then
ipc.writeLvar("L:ASD_SWITCH_TRANS_PUMP_LEFT",2)
elseif ipc.testbutton(3,3) == false then
ipc.writeLvar("L:ASD_SWITCH_TRANS_PUMP_LEFT",1)
end
[/CODE]

Here's a different example that I picked up from jbellardi's CAR_C90_CD.lua script. (a fantastic script by the way) That turns off the recognition lights by triggering the FSX "Toggle Recognition Lights" function.

[CODE]
RLI = logic.And(ipc.readUW(0x0D0C), 64)
if RLI ~= 0 then
ipc.control(66377)
end
[/CODE]

My uneducated interpretation of this is that it is reading the condition of the recognition lights and if they are on it triggers the toggle function to turn them off. I would like to right a variation of this that accomplishes the reverse so I can place the two pieces of code in an "If then else" statement that reads my physical panel switch and if it is set to on and the lights are off, toggle them, conversely if the physical switch is set to on and they are already on do nothing.

I have attempted all sorts of variations of the if RLI statement to see if I could figure out how to detect when the recognition lights where on, but no luck. I don't understand enough of what the output of that "logic.and" statement is to make it work. Any advice or direction would be greatly appreciated!

I also suspect I could do much more of this myself if I better understood how to capture lua code related to specific action. I am capturing code in log files, be weeding through hundreds of lines to finds the secret formula is a bit more challenging than I thought it would be. IS there anyway to get a lua log to only capture events that result from an on screen action that I take such as clicking the Master Caution switch, or will I always need to decipher the required elements from the stream of code.

Thanks in advance for any help!!!

Tom G.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.