
ark1320
Members-
Posts
670 -
Joined
-
Last visited
-
Days Won
17
Content Type
Profiles
Forums
Events
Gallery
Downloads
Everything posted by ark1320
-
Sorry, my fault, let me try to be clearer. I have rewritten the TOD pause script. When run it first displays an "Enter time to TOD" message in the wnd window and a data entry event.timer() starts which gives the user 2 minutes in which to enter the desired time until TOD pause. If there is no entry within the time limit the script closes with a timeout message. If a TOD time is entered successfully, a TOD event.timer() is started which, as I understand it, will automatically cancel the data entry event timer. A TOD Pending message is displayed until the TOD event timer times out and the called timer function pauses the sim. As for cancelling a pending pause, I've changed things so once a TOD pause is pending, hitting Enter exits the script thus cancelling the pending pause. I wanted to ask if I am correct that rerunning a running script automatically cancels all the events in the first instance of the script? Best, Al
-
With the "ask" substitute the reply happens as soon as the data is entered assuming the data is followed by the required Enter key, so it seems a simple 'one-time' timeout check at the end of the allowed data entry time will work fine. (Edit: I see John just said the same above) With the current TOD pause script I check the time every 10 sec using a timing loop based on ipc.sleep(10000). I thought 10 sec was plenty accurate even for short times while not putting any significant load on the PC. But, based on your event.timer info (25 days, WOW!) , I might as well do away with the timing loop and just use a "one time check" timer like event.timer(TODtime, "pause_sim"). As I understand it, this TOD event timer will replace the event.timer() used to get the TOD pause time value from the user since you can have only one event timer active at a time per Lua script. Pending (future) TOD pauses can be cancelled by simply rerunning the script -- i.e, the script works in a toggle TOD pause on - TOD Pause off manner. Thanks for the timer info, Al
-
Great - thanks. The get_asked_data.lua script uses ipc.exit() to cancel all the pending events since the script ends when the data is entered, but the TOD_PauseMSFS.lua script mentioned above will make good use of the event.cancel() fix since the script may run for hours (until TOD) after the TOD time is entered. So can't use ipc.exit() to cancel events. I would like to clarify something about the mytimer() function in your original askTest.lua script. function mytimer(time) closeafter = closeafter - 500 if closeafter <= 0 then wnd.close(w) w = 0 event.cancel("mytimer") ............. event.cancel("keyPressed") ipc.log("No number entered: timed-out") end end My understanding is you use event.timer(500, "mytimer") to call this function every 500 ms (milliseconds) to check if data has been entered within the allowed time period of 3600000 ms or 60 minutes, and if not all events are cancelled. My question is, if in a request for data application we were to set the allowed time for data entry to a much smaller time, say 5 minutes (300000 ms) could we just use a 5 minute interval, e.g. event.timer(300000, "mytimer')? What I'm asking is why check repeatedly if data has been entered instead of just checking once at the end of the total allowed data entry time? Does this perhaps have something to do with the max allowed value for the interval in ms? Thanks, Al
-
Sure -- be glad to do a brief writeup and put the 'ask' scripts into the Contributions section. I also have a TOD_PauseMSFS.lua that will pause MSFS at a user set Top of Descent time that makes use of your basic script, so will also put that into the Contribution section. Al
-
I now generate events for both the upper and lower case letter keys j= 65 while j <= 90 do event.key(j, 0, "keyPressed") -- Lower case letters a to z event.key(j, 1, "keyPressed") -- Upper case letters A to Z j = j + 1 end and process the keycodes like this: if keycode >= 65 and keycode <= 90 then -- convert keycodes to char codes charcode = keycode + (1 - shifts)*32 -- convert keycode to lower case if shifts = 0 by adding 32 to keycode, shifts = 1 for uppercase elseif keycode >= 96 and keycode <= 105 then -- for Num0 to Num9 charcode = keycode - 48 elseif keycode >= 106 and keycode <= 111 then -- Numpad * + - . and / (note there is no 108 keycode) charcode = keycode - 64 else charcode = keycode end enteredText = enteredText .. string.char(charcode) -- else display next char entered With this I get upper and lower case letters and all Numpad key working as I expected. I now better understand the difference between key codes which refer to a physical key on the keyboard, and char codes which represent an ASCII character. I updated the script code posted above and also attached it here along with the calling function in case anyone might be interested. Best, and many thanks, Al ask_for_data _function_definition.lua get_asked_data.lua
-
OK, I think I get it now; event.key() only works with virtual key codes, and there doesn't seem to be any virtual key codes for lower case letters in the list in the Advanced User's Guide. I guess my thinking (or lack thereof) was skewed by my experience with ipc.ask() which works with both upper and lower case letters, etc. Sorry for my confusion on this. Thanks, Al
-
Pete, I don't know why with the script above the numberpad keys, with numlock on, are returned and displaying incorrectly, e.g., num1 to num9 display as the lower case letters a to i. I am using the keycodes per the table in the Advanced Users guide. There was some issue, now resolved I believe, with FSUIPC7 getting wrong numpad key codes through SimConnect, and John provided some kind of temporary work-around. I also don't understand why with the script above keys a to z display as UPPER case using keycodes 65-90 since I'm not using the Shift option in event.key(). Maybe that is just how wnd.text() works? The little file attached which displays the keycode of a pressed key shows the lower case letter keycodes as 65-90 with Shift off. If 65-90 were in fact upper case keycodes, what are the lower case keycodes for a to z? Thanks to you and John this certainly has been a useful and interesting learning experience for me. Al KeyCodes3.exe
-
Pete, Here is a version of the above "events" lua script that on one hand is more compact code-wise and on the other was expanded to include letters and the numpad digits. The numpad digits don't work (they actually provide the ' char and the lower case letters a - j for num0 to num9. I think this is because of what John had to do to make the numpad keys work through SimConnect. The letters do work, although they are all returned as upper case for some reason. So this script is using 47 event.key events -- what are some of the considerations regarding the practical limit on the number of events the system can monitor at one time? -- Adjust the numbers here to set your Window position and size -- (x, y, sizex, sizey), w is the window's 'handle' (identifier) local w = wnd.open("Get Num Input", WND_FIXED, 800,100,425,60) -- Window size and location wnd.show(w, WND_TOPMOST) -- keep window on top of screen -- These set the colours and font to be used. -- The size "-4" means the largest to fit 4 lines in the window wnd.backcol(w, 0x000) wnd.textcol(w, 0x6c0) wnd.font(w, WND_ARIAL,-3) -- Update the display at 500 msec intervals (see event at end) local interval = 500 -- 1/2 second local closeafter = 120000 -- 2 minutes to provide data before timeout local enteredText = "" -- init enteredText by user to nothing (cleared) local data_request = ipc.get ("DATA_REQUEST") local displayText = data_request wnd.text(w, displayText) -- display message requesting input function mytimer(time) -- close window after 2 minutes closeafter = closeafter - 500 if closeafter <= 0 then ipc.set("DATA_ANSWER", "*") -- * indicates timed out or an error condition (see below) wnd.close(w) w = 0 ipc.exit() -- cancel all event.key events and event.timer event and exit script end end function keyPressed(keycode, shifts, downup) -- close window after CR (Enter) key and display enter text (e.g., number) if keycode == 0x0D then if enteredText == "" or enteredText == nil then enteredText = "*" -- * indicates timeout (see above) or error condition end ipc.set("DATA_ANSWER", enteredText) wnd.close(w) w = 0 ipc.exit() -- cancel all event.key events and event.timer event else -- else display next char entered if keycode >= 65 and keycode <= 90 then -- convert keycodes to char codes charcode = keycode + (1 - shifts)*32 -- convert keycode to lower case if shifts = 0 by adding 32 to keycode, shifts = 1 for uppercase elseif keycode >= 96 and keycode <= 105 then -- for Num0 to Num9 charcode = keycode - 48 elseif keycode >= 106 and keycode <= 111 then -- Numpad * + - . and / (note there is no 108 keycode) charcode = keycode - 64 else charcode = keycode end enteredText = enteredText .. string.char(charcode) -- else display next char entered newDisplayText = displayText .. enteredText -- newDisplayText = original window message + user entered text wnd.clear(w) wnd.text(w, newDisplayText) end end -- Adjust timing to taste: 500 = 1/2 second event.timer(interval, "mytimer") -- call function "mytimer" every 'interval' in time -- valid data characters i = 48 while i <= 57 do -- digits 0 to 9 event.key(i , 0, "keyPressed") i = i + 1 end j= 65 while j <= 90 do event.key(j, 0, "keyPressed") -- Lower case letters a to z event.key(j, 1, "keyPressed") -- Upper case letters A to Z j = j + 1 end k= 96 while k <= 111 do -- number pad keys with numlock on event.key(k , 0, "keyPressed") k = k + 1 end -- additiona virtual keycodes, see FSUIPC Advanced User's Guide pages 19-20 event.key(8, 0, "keyPressed") -- Backspace event.key(13, 0, "keyPressed") -- Enter event.key(32, 0, "keyPressed") -- space bar event.key(135, 0, "keyPressed") -- Numpad Enter key
-
Pete -- very clever! Here's what I came up with. The definition of the calling function as an alternate to ipc.ask() is ask_num_data(request_string). I used the repeat - until because John's askTest() uses an event.timer. function ask_num_data(request_string) ipc.set("DATA_REQUEST", request_string) ipc.set("DATA_ANSWER", request_string) ipc.runlua("C:\\Users\\Al\\Documents\\....\\FSUIPC7\\Modules\\get_num_data.lua") repeat data_returned = ipc.get("DATA_ANSWER") ipc.sleep (100) until data_returned ~= request_string return data_returned end So a user would use something like this when requesting data. gs = ask_num_data(" Enter Ground Speed ") The accompanying get_num_data.lua script that is called, as you suggested, by ask_num_data(request_string) is below (the few changes I made to John's script are in purple). The script returns an * that can be tested for to indicate a timeout or error condition. It all seems to work but I'm certainly open to any suggestions. This script will get much smaller when John fixes the bug in FSUIPC7 that he mentioned so one event.cancel() below will cancel all the same pending events. Thanks for ALL the help, Al get_num_data.lua -- get_num_data.lua Script works with function call ask_num_data(request_string) as an alternate to standard ipc.ask() for getting numerical input in MSFS -- Script is a slight modification of the askTest.lua script by John Dowson -- 2Jan2021 -- Adjust the numbers here to set your Window position and size -- (x, y, sizex, sizey), w is the window's 'handle' (identifier) local w = wnd.open("Get Num Input", WND_FIXED, 800,100,425,60) -- Window size and location wnd.show(w, WND_TOPMOST) -- keep window on top of screen -- These set the colours and font to be used. -- The size "-4" means the largest to fit 4 lines in the window wnd.backcol(w, 0x000) wnd.textcol(w, 0x6c0) wnd.font(w, WND_ARIAL,-3) -- Update the display at 500 msec intervals (see event at end) local interval = 500 -- 1/2 second local closeafter = 120000 -- 2 minutes to provide data before timeout local enteredText = "" -- init enteredText by user to nothing (cleared) local data_request = ipc.get ("DATA_REQUEST") local displayText = data_request wnd.text(w, displayText) -- display message requesting input function mytimer(time) -- close window after 2 minutes closeafter = closeafter - 500 if closeafter <= 0 then ipc.set("DATA_ANSWER", "*") -- * indicates timed out or an error condition (see below) wnd.close(w) w = 0 event.cancel("mytimer") event.cancel("keyPressed") event.cancel("keyPressed") event.cancel("keyPressed") event.cancel("keyPressed") event.cancel("keyPressed") event.cancel("keyPressed") event.cancel("keyPressed") event.cancel("keyPressed") event.cancel("keyPressed") event.cancel("keyPressed") event.cancel("keyPressed") end end function keyPressed(keycode, shifts, downup) -- close window after CR (Enter) key and display enter text (e.g., number) if keycode == 0x0D then if enteredText == "" or enteredText == nil then enteredText = "*" -- * indicates timeout (see above) or error condition end ipc.set("DATA_ANSWER", enteredText) wnd.close(w) w = 0 event.cancel("mytimer") event.cancel("keyPressed") event.cancel("keyPressed") event.cancel("keyPressed") event.cancel("keyPressed") event.cancel("keyPressed") event.cancel("keyPressed") event.cancel("keyPressed") event.cancel("keyPressed") event.cancel("keyPressed") event.cancel("keyPressed") event.cancel("keyPressed") else -- else display next char entered enteredText = enteredText .. string.char(keycode) newDisplayText = displayText .. enteredText -- newDisplayText = original window message + user entered text wnd.clear(w) wnd.text(w, newDisplayText) end end -- Adjust timing to taste: 500 = 1/2 second event.timer(interval, "mytimer") -- call function "mytimer" every 'interval' in time event.key(0x30 , 0, "keyPressed") -- 0 -- call "keyPressed" function if 0 key pressed event.key(0x31 , 0, "keyPressed") -- 1 event.key(0x32 , 0, "keyPressed") -- 2 event.key(0x33 , 0, "keyPressed") -- 3 event.key(0x34 , 0, "keyPressed") -- 4 event.key(0x35 , 0, "keyPressed") -- 5 event.key(0x36 , 0, "keyPressed") -- 6 event.key(0x37 , 0, "keyPressed") --7 event.key(0x38 , 0, "keyPressed") --8 event.key(0x39 , 0, "keyPressed") --9 event.key(0x0D , 0, "keyPressed") -- return
-
Pete, your patience is quite amazing. I think I have done a poor job of explaining what I see as the problem, or I’m not astute enough to fully understand what you are telling me, or maybe both. In any case, if the ipc.ask() function worked, I might have a main program script like this: -- main program new_alt = ipc.ask(“enter altitude”) code here to process altitude input new_hdg = ipc.ask(“enter heading”) code here to process heading input new_gs = ipc.ask(“enter ground speed”) code here to process ground speed input -- end main program What I ‘m trying to do is write a new function (not stand alone program) called get_input() that is based on John’s stand alone askTest script. This new function would be defined at the top of the program above and then I could call it in place of the three ipc.ask() functions, e.g., new_alt = get_input (“enter altitude”), etc. The challenge I have is that while each ipc.ask() function would in essence stop program execution and wait for the user to enter the requested data (followed by a return character), I can’t figure out how to make the replacement get_input() function based on John’s work do that –as a called function it executes in a ‘flash’ and returns to the main program before the user has time to enter any data. How to add that ‘wait for input feature’ that ipc.ask() has to the replacement get_input() function is what I’m struggling with. Stated more generally, the issue is how do you prevent a called function from returning to the main program until a particular character is detected if , as you explained above, you can't use 'loop' constructs (repeat-until, while-do, etc) that don't relinquish control because the called function makes use of event type operations such as event.key(). Hope that clarifies the problem as I see it. Thanks you, Al
-
Just to clarify, I just realized that I was not quite correct above in that John's script does not use a discrete return instruction since it is not written as a function, but when a return character is detected, all events are cancelled and the program just ends. Al
-
Yes, John's script does that and it works fine as a stand alone Lua program. It is when I try to incorporate it into the form of a function to be called from a main program, the function 'completes' before any key presses can be detected and returns to the calling program which then of course 'continues on'. You have been more than generous with your time on all this, I will continue to think about it and see what I can figure out. Many thanks, Al
-
The standard ipc.ask() function does not return an input until a Return character is detected. With this in mind, I have been trying to rewrite John's askTest.lua script in the form of a function so it can be called from a main program when needed. What I can't figure out is how to prevent the return from the askTest() function back to the main calling program until after the Return key has been detected thus indicating the input process has been completed. Thanks for any suggestions, Al
-
AH! That's what I didn't understand. Thank you, Pete! I will try what you have suggested. Best, Al EDIT: Now works as expected -- many thanks again!
-
My issue here is when the counter is running, the event.key() function does not seem to work. I changed the test script to the below. The counter counts up and displays correctly, but when I press the 0 key, the count is not reset as I would expect . It seems the event.key(0x30 , 0, "ResetCount") function does not detect a 0 key press and call the ResetCount function to reset the counter. I don't understand why event.key() is not working. The 0 key is not assigned in FSUIPC7 or in MSFS, so it is not being 'trapped' as best as I can tell. I also tried detecting other number keys in this test script, none work. Thanks for any ideas, Al function ResetCount() k = 0 end -- Main program w = wnd.open("Counter test", WND_FIXED, 800,100,200,30) wnd.backcol(w, 0x000) wnd.show(w, WND_TOPMOST) wnd.textcol(w, 0x6c0) wnd.font(w, WND_ARIAL,-1) event.key(0x30 , 0, "ResetCount") -- detect 0 keypress k=0 while k <= 3600 do k = k+1 wnd.text(w, "Count = "..k) ipc.sleep(1000) end
-
I have been trying to develop a function based on the askTest.lua script that could be called from a main program wherever numerical input was needed -- no success so far. So to make sure I understood correctly how things worked, I wrote the following little test script. I expected that once the event.key() function was executed, then if I pressed the 5 key while the k counter was counting up, the event.key function would detect the key press and the DisplayTest function would be called and Test would be briefly displayed. But as far as I can tell, nothing happens when I press the 5 key -- all I see is k continuing to count up without any interruption. Even if I disable the display of k, I get no response to pushing the 5 key. So either there is something fundamental I don't understand, or maybe it is a SimConnect text display problem? Best for the New Year! Al function DisplayTest() ipc.writeSTR(0x3380, "Test") ipc.writeSW(0x32FA, 3) ipc.sleep(3000) end -- Main program event.key(0x35 , 0, "DisplayTest") -- 5 digit k=0 while k <= 3600 do k = k+1 ipc.writeSTR(0x3380, k) ipc.writeSW(0x32FA, 1) ipc.sleep(1000) end
-
Ah, I have learned something! Thanks Pete and John for the clarification. As you can tell, my programming experience has been limited. I expect you could also use a return if you need to exit the function early before the end, e.g., in the middle of the function body based on some data variable. Best, Al
-
What I'm asking about regarding the return instruction is I normally think of a function definition as having the form: function name( params ) body of the function return -- return to where function was called from end I was surprised to see that the mytimer() and keyPressed() functions did not have a return instruction to transfer code execution back to the calling location. BTW, do you have any idea at this point about when FSUIPC7 will be updated again? Thanks for your time with all this, Al
-
That fixed the issue with resizing/moving the window -- thanks. Just to clarify, so if an event function call like event.key() is called as part of a larger function, does that event remain active even after the program returns from the larger function? BTW, I noticed the mytimer() and keyPressed() functions did not end with a Return instruction -- does that have something to do with the nature of the event .cancel() function calls contained in the mytimer() and keyPressed() functions? Thanks, Al
-
John, I'm trying to understand how the askTest script works and thinking about how to incorporate the askTest code in a larger program. At first I was just going to make the askTest code into a 'large' function that could be called as needed, but now I'm wondering if that will work with the event type function calls the script contains. Can event calls be internal to a called function, or do they essentially have to be part of the main program since they just sit and wait to be triggered? It seems from the askTest code that if you have 10 event.key() functions then you need 10 event.cancel() functions -- apparently one event.cancel () function will not call all the event.key() functions? BTW, I see the line event.cancel("mytimer2") but do not see any function named mytimer2. I assume the 2 in the function name is a typo. Thanks again for the script, Al
-
Hi John, Thanks very much for the script. I've been trying it a bit and it seems to work (although just a few times nothing happened when I pressed the key I have assigned to run it -- maybe some kind of timing glitch). What didn't work is changing the numbers in the code line that defines the display window local w = wnd.open("Asking for inout: test", WND_FIXED, 500,200,500,60) Nothing I did made any difference for some reason. I have tried restating both FSUIPC7 and the sim after changing these numbers but don't see any change when the script is run. I will keep experimenting with the script a bit later today. Al
-
Agree! And I really appreciate your and John's support efforts. Al
-
I have to wonder if Asobo realizes just how messed up their text functions are, at least when used through SimConnect. Even when a Lua single line text display shows up correctly, if often displays multiple times for no apparent reason. If you could come up with a work around, that would certainly be VERY helpful. Thanks, Al
-
Hi John, Your update to FSUIPC7 seems to work as expected. Thanks very much! Al
-
I know the Numpad number keys now work correctly, but don't see anything I recognize in the SDK about the keys I mentioned above. Thanks for the response, Al