New question: making a repeat loop wait on button press

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
streamline
Posts: 10
Joined: Wed May 13, 2009 4:04 am

New question: making a repeat loop wait on button press

Post by streamline » Thu Jul 16, 2009 3:09 pm

Edit: I have a new question, instead of creating a whole new thread I've posted it at the bottom.

-----------------------------
Hi,

I've done much searching on this forum and in the Rev dictionary to no avail.

I'd be very glad if someone could point me in the right direction for solving two little problems.

First: how to disable keyboard entry for an entire card/stack OR how to ignore certain keys if they are pressed after an answer dialog comes up. Here's a script excerpt:

Code: Select all

     answer "Press a button to continue:" with "Quit" and "Proceed to next pair"
        if it is "Quit" then
           exit repeat
        end if
I don't want users to be able to press Q, P, space, enter or return to select an answer, I want them to use the mouse to select a button. I tried playing with stuff like keyDown, returnKey etc but couldn't get anything to work.

Secondly - in the script above you can see I wrote "Quit" before the other option - yet on the program, when the dialog box actually pops up, the buttons are the other way around. It's not really a problem, I'm just curious why this happens.

But related to that, I have another script excerpt which utilises an if statement within an if statement, I'd be interested to know if this is taboo or if there is a better/more efficient way of achieving the same thing.

Code: Select all

     answer "Which face is more familiar?" with "Right face" and "Left face"
     if (it is "Right face" AND gCase is pRIGHT) OR (it is "Left face" AND gCase is pLEFT)
     then
        put "IDENTIFIED" after gData
     else
           if (gCase is pDIFF) OR (gCase is pNONE)
           then
              put "-" after gData
           else
              put "NOT IDENTIFIED" after gData
           end if
     end if
Thanks for reading!
Last edited by streamline on Fri Jul 17, 2009 6:16 am, edited 2 times in total.

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Post by Klaus » Thu Jul 16, 2009 4:07 pm

Hi streamline,

some thoughts...

1. I would insert a little frontscript before "answer"- or "ask"-ing th user and remove it afterwards.

Like this in an invisible button "tFront1"

Code: Select all

on keydown tKey
  put tKey into tNirvana
end keydown

on keyup tKey
 put tKey into tNirvana
end keyup

on returnkey
 get "tNirvana"
end returnkey
### etc. for whatever you want to catch
Now you could do this when calling your dialogs:

Code: Select all

...
insert script of btn "tFront1" of cd X of stack Y into front
## important to give complete description!

## do your ASK or ANSWER stuff
remove script of "tFront1" from front
...
You get the picture, not tested however :-)

2. On my mac the line:
answer "Press a button to continue:" with "Quit" OR "Proceed to next pair"
Gave me "Quit" on the left side of the dialog!?

Hint: "OR" is the official syntax for a "button list" in dialogs.

3. Using nested "if... then... else..." is OK!
I personally prefer "switch" most of the time, since it makes the code more readable like this:

Code: Select all

...
answer "Which face is more familiar?" with "Right face" and "Left face"
put it into tAnswer

switch
case tAnswer = "Right face" AND gCase is pRIGHT
case tAnswer = "Left face" AND gCase is pLEFT
  put "IDENTIFIED" after gData
  break
  
case gCase = pDIFF
case gCase = pNONE
  put "-" after gData
  break
  
default
  put "NOT IDENTIFIED" after gData
  break
end switch
...
Best

Klaus

streamline
Posts: 10
Joined: Wed May 13, 2009 4:04 am

Post by streamline » Fri Jul 17, 2009 1:12 am

Klaus wrote:1. I would insert a little frontscript before "answer"- or "ask"-ing th user and remove it afterwards.
Worked perfectly. Handy workaround trick to remember for later.
Klaus wrote:2. On my mac the line:
answer "Press a button to continue:" with "Quit" OR "Proceed to next pair"
Gave me "Quit" on the left side of the dialog!?

Hint: "OR" is the official syntax for a "button list" in dialogs.
I fixed my script and used OR instead of AND but the order is still reversed. I'm using Windows by the way. But, it's not a problem luckily, just odd...
Klaus wrote:3. Using nested "if... then... else..." is OK!
I personally prefer "switch" most of the time, since it makes the code more readable like this:
I wasn't quite sure on how to do what I wanted with switch and your example explained it, so I'll use switch instead.

Thanks for the help Klaus. :)

streamline
Posts: 10
Joined: Wed May 13, 2009 4:04 am

Post by streamline » Fri Jul 17, 2009 6:21 am

New question:

The reason I implemented answer boxes in the first place was to halt the repeat loop they run in and wait for an answer. However I would far prefer buttons embedded in the card to appear, the problem is that when I tried this method it showed the group (which contains the question field and 2 answer buttons) but didn't wait for an answer and instead continued on with the loop.

Is there any way to get the repeat loop to wait for the user to press a button before it hides the buttons again and continues with the rest?

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Post by Klaus » Fri Jul 17, 2009 2:45 pm

Hi streamline,

1. The buttons in dialog are "swapped by design" to take platform differences into account :)
Since on Windows the order of the buttons is different than on a Mac and Rev just compensates this fact.

The last button in this list for the dialog will be shown as the OS "default"button on
Mac it appears at the right side of the dialog on
Windows the default button is on the left side.

So this is correct behaviour which you need to take into account in your app ;)


2. Ask and answer dialogs
Scripts halt since a dialog opens as a modal window which blocks almost everything.
If you want to implement this functionality without modal windows you could cut your scripts into small "sub scripts" that you call successively.

That's what I would do :)


Best

Klaus

Post Reply