Jump to content
The simFlight Network Forums

Alternative to ipc.ask()


Recommended Posts

I have a number of Lua scripts that make good use of ipc.ask(). Unfortunately, ipc.ask() does not work reliably in MSFS due to current limitations of the SDK. So with the significant help of Pete and John Dowson I developed the two attached Lua scirpts that work together to provide a temporary (hopefully) alternative to ipc.ask().

The ask_for_data_function_definition is a function that when invoked by an instruction asking for data in your main Lua script, in turn runs the get_asked_data.lua script that must be in the same folder with FSUIPC7.ini.  The get_asked_data.lua script returns the requested data or an * (asterisk) indicating an error. Perhaps this is best explained by example. If you had a script that would normally use ipc.ask() it might look like this:

-- Your Program code


alt = ipc.ask( "Enter the new desired altitude")


gs = ipc.ask("Enter ground speed")


-- end of Your Program code

With the alternative to ipc.ask we have this.

-- ask_for_data_ function

function ask_for_data(request_string)
         ipc.set("DATA_REQUEST", request_string)
         ipc.set("DATA_ANSWER", request_string)
         ipc.runlua("C:\\Users\\..... insert path to your Lua scripts....\\get_asked_data.lua")     --note Lua syntax requires the use of the double back slashes.
          data_returned = ipc.get("DATA_ANSWER")
          ipc.sleep (100)
         until data_returned ~= request_string
         return data_returned

-- Your Program code


alt = ask_for_data( "Enter the new desired altitude")    --ipc.ask() alternative function call


gs = ask_for_data("Enter ground speed")                      --ipc.ask() alternative function call


-- end of Your Program code


So the major change is the ask_for_data(request_string) function has been added to the original program code.  When the application program gets to an ask_for_data() request, the user has 2 minutes to provide the data (followed by the Enter key) or an * is returned to signal a data request timeout error has occurred. The returned data string can consists of upper and lower case letters, numbers, space, and Numberpad characters with NumLock on.   At the beginning of the main ask_for_data code is the variable error_string, currently set to "*".  If the asterisk is a valid value in your application, you can change this, e.g., error_string = "!ERR!", etc., that better fits your application.  Whatever you use, you probably would want to test for it in your application.   The data timeout time is set by the variable data_entry_time, also located at the top of the main get_asked_data code, and so can be easily changed as well.

Once a request for data window is displayed, there is a slight delay (as second or two) before a key stroke will be recognized. I think this delay is caused by the time it takes the ask_for_data() script to establish all the key detection events each time it is run.

Edit: See post below if only using purely numerical data.




ask_for_data _function_def.lua



  • Like 1
Link to comment
Share on other sites

The files ask_for_num() and get_asked_num() attached below are versions of the files ask_for_data() and get_asked_data() (post above) but only work for purely numerical values -- no letters -- and as a result there is less delay in detecting an input since each time called get_asked_num() does not require establishing events for all the lowercase and uppercase letters.






Link to comment
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
  • 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.