panchristo Posted July 9, 2010 Posted July 9, 2010 Hi there! I have a script going into endless loop and can't figure why, here's the story: I initiate a script for selecting a record in a pop-up window. To oblige the user to either select or cancel, I use a loop script step with an Exit Loop If set to recognize if a "cancel" result from a subscript has been returned. When I attach the cancel subscript to a button it works like a charm. But when I load it through an OnLayoutKeystroke Trigger (trapping if ESC is pressed) it returns an error 20, closes the window (as it should) and then pauses endlessly, not exiting the Loop. Can anyone help?
bcooney Posted July 9, 2010 Posted July 9, 2010 Managing pauses is a challenge. This is a link to a demo of a popup select window with a cancel option. hth, Barbara http://fmforums.com/forum/showpost.php?post/350708/
panchristo Posted July 10, 2010 Author Posted July 10, 2010 Hmm. Nice and simple I have to admit, because as an amateur I thought it should have a loop in order to be modal. On second thought though, my pop-up is used to select a value by leading to consecutive layouts until the desired value appears (thought this as an alternative to a difficult-to-build-and-maintain-hierarchy), which also uses arrow keys and Enter/Return as a selection key to facilitate easy data-entering. Therefore, it would cause your script to exit. Any other ideas?
bcooney Posted July 10, 2010 Posted July 10, 2010 Why would it cause my script to exit? Each go to layout would call another script and the buttons attached to this navigation would Pause the current script. I'm not a fan of wizard-like interfaces. Hope this works out for you.
panchristo Posted July 11, 2010 Author Posted July 11, 2010 As I said, I use the Enter key as a selection button in the list view each popup displays. I use the code function to see if ENTER/RETURN is pressed and run the "selection script". Therefore it can't be assigned to just unpause the current script. Do you have any other ideas how this could be done? Remember up/down for navigation in list view (no editing) and ENTER/RETURN for selecting!
bcooney Posted July 11, 2010 Posted July 11, 2010 I can't picture what you're doing. List views and drop down lists and popup menus are not the same thing. So, when you say "list view," what are you referring to? What is your goal--no mouse use? Can you post the script and some screen shots or a simple demo file?
panchristo Posted July 11, 2010 Author Posted July 11, 2010 I can't picture what you're doing. List views and drop down lists and popup menus are not the same thing. So, when you say "list view," what are you referring to? What is your goal--no mouse use? Can you post the script and some screen shots or a simple demo file? Didn't say anything about value lists... Can't send sth now, please see if you can get the picture again: Selecting a storage space in my application goes as follows: 1. A pop-up window comes up (modal) in list view displaying records. Navigation between records can be achieved by using the OnlayoutKeystroke trigger. 2. If arrow keys (up/down) are pressed (determined by CODE function) the triggered script moves respectively one record up or down. 3. When ENTER is pressed (again recognized by the Code function), it selects the record and leads to the next layout (GTRR - in same popup) until the desired level of detail is reached.(i.e. Area>Building>Room>Section>Column>Row>Shelf>Box) 4. The last keystroke defined in the script triggered everytime there is a keystroke is ESC, which starts a subscript to cancel the process (close window, clear var e.tc.). All of this in order to speed up the process and minimize mouse use. The script controlling the selection process, pauses in a loop and doesn't exit (User Abort off) unless a predefined subscript result is returned (i.e. ok or cancel). My only problem is when the cancel subscript is run by the ESC keystroke (again through the OnLayoutKeystroke trigger). It then unexpectedly returns an error#20, and doesn't return the expected subscript result (cancel), so the main script remains in endless loop. Otherwise, if the same subscript is called from a button, works fine. Have I made it a bit clearer now?
David Jondreau Posted July 12, 2010 Posted July 12, 2010 What are the script steps in the "cancel subscript"?
panchristo Posted July 12, 2010 Author Posted July 12, 2010 Not quite sure about what you mean (not native Emglish speaker). Here are the script steps (maybe I should have done that in the beginning) == SelectProcess == Freeze Window Allow User Abort [off] New Window GoTo layout [select Area] Loop Exit Loop if [Get(ScriptResult)="cancel"] Pause Script [indefinetely] End Loop Exit Script == Cancel == Close Window ExitScript [cancel] I haven't included the key navigation script as it works just fine.
panchristo Posted July 12, 2010 Author Posted July 12, 2010 (edited) Error#20 = Command/operation canceled by triggered script Does this mean that although the SelectProcess Script runs first, the OnLayoutKeystroke-triggered Cancel is not considered a subscript and therefore doesn't pass the parameter (cancel)? Because otherwise, if the script is run by the button on the layout it works as it should. Can't really find another reason for this. I suspect the solution would be to issue a variable in the beggining of the SelectProcess script that captures this state and update it. This would have to be Global I guess. Can anyone suggest another solution to the problem? UPDATE: So far tested this seems to be the solution. Edited July 12, 2010 by Guest
Vaughan Posted July 12, 2010 Posted July 12, 2010 I usually set up modal windows in a much simpler manner. I have a looping script like yours. I then manage the user interface very carefully so that the user can not run scripts that resume, exit or halt the current script (unless I intend them to). The interface will have buttons set to either resume or exit the current script, depending on whether the button is meant to continue or cancel the process. So I'd have a Cancel button on the screen that runs a script containing the Close Window step (as well as other stuff that might need to be done). The Exit parameter on the button will kill the currently paused script, then close the window. In more complex situations I have used global variables to "remember" whether a cancel script has run, but either way there still needs to be an event to resume the paused script. This is always a button with the Resume option selected. As for all of the other scripts and triggers you are running, I have never done anything so complex and would never attempt to. I leave the interface to native FMP commands as much as I can (eg, the default record navigation shortcut keys). Complexity with scripts, especially with script triggers, increases rapidly and I strive to keep the level as low as I can.
panchristo Posted July 12, 2010 Author Posted July 12, 2010 Thanks Vaughan, I think I have found out the problem (as I said above) and now with the Global Variable defined it seems to work properly. One last question though, just to confirm my knowledge: Once you set a variable to "" it is as though it doesn't exist anymore right? I wouldn't want to mess yet with two many of them, so doing this in the end of the script would get it out of the way when not needed, wouldn't it?
Fitch Posted July 12, 2010 Posted July 12, 2010 > Once you set a variable to "" it is as though it doesn't exist anymore right? Correct, fire up the Data Viewer and you can verify this.
Recommended Posts
This topic is 5248 days old. Please don't post here. Open a new topic instead.
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 accountSign in
Already have an account? Sign in here.
Sign In Now