Answer function

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

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Answer function

Post by mwieder » Fri Nov 13, 2020 5:14 pm

Well, yes.

The answer dialog is launched on mouseUp, so the mouseDown message passes along the message path until it finds a handler that traps it.
In your case, since you've got the data stack in the message path, it'll get the message before the answer dialog is invoked.
Then when the mouseUp message comes along, the answer dialog appears.

odysseus
Posts: 42
Joined: Tue Aug 25, 2020 2:15 pm

Re: Answer function

Post by odysseus » Fri Nov 13, 2020 7:26 pm

No, I've got a button that triggers the answer dialog on mouseUp, and I've trapped the mouseDown in it, so no mouseDown is sent. The answer dialog appears, and if either button is pressed, the mouseDown handler in the data stack is triggered, with the target shown as 'Button Yes' or 'Button No', so the mouseDown is definitely coming from the answer buttons.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9823
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Answer function

Post by FourthWorld » Fri Nov 13, 2020 7:33 pm

This raises a question: should we add mouseDown stubs to the answer and ask dialogs to prevent this in the future?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Answer function

Post by mwieder » Fri Nov 13, 2020 8:50 pm

odysseus- in your mouseDown handler in the data stack, insert a breakpoint as the first line in the handler.
See if the breakpoint is hit *before* the answer dialog comes up.

[update] I just reread the previous two comments.
Yeah, I think the mouseDown message is being passed on by the answer modal dialog.
That just seems wrong.

odysseus
Posts: 42
Joined: Tue Aug 25, 2020 2:15 pm

Re: Answer function

Post by odysseus » Fri Nov 13, 2020 9:59 pm

I think it would be more correct to say that the mouseDown message is generated by the buttons in the answer dialog. The fact that they don’t generate a mouseUp says to me that it’s unintentional (dare I say a bug).

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Answer function

Post by mwieder » Fri Nov 13, 2020 10:38 pm

Yes - that's what I meant to say. IMO modal dialogs shouldn't generate side effects.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Answer function

Post by dunbarx » Fri Nov 13, 2020 11:26 pm

I think it would be more correct to say that the mouseDown message is generated by the buttons in the answer dialog. The fact that they don’t generate a mouseUp says to me that it’s unintentional (dare I say a bug).
I don't understand.

If I have this in a button:

Code: Select all

on mouseUp
  breakpoint
end mouseUp

on mouseDown
   answer "Down" with "OK, down"
end mouseDown
If i click on the button, I get the "Down" answer dialog. As I said earlier, "mouseUp" never fires. Where are youse guys getting that it ever does?

craig

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Answer function

Post by mwieder » Sat Nov 14, 2020 12:29 am

Craig-

Put a mouseDown handler in a stack script.

on mouseDown
breakpoint
end mouseDown

In a *separate* stack, put a button with the script

on mouseUp
start using stack "" -- the name of the first stack
answer "what?" with "dunno" and "whatever"
end mouseUp

Now click the button.
The answer dialog will appear, but clicking either of the two buttons on it will trigger the breakpoint because the modal dialog is leaking the mouseDown message.

odysseus
Posts: 42
Joined: Tue Aug 25, 2020 2:15 pm

Re: Answer function

Post by odysseus » Sat Nov 14, 2020 12:57 am

Just to clarify, In my button I put:

on mouseUp
answer “Hello” with “Yes” or “No”
end mouseUp

on mouseDown
—do nothing
end mouseDown

So the mouseDown is trapped and not sent

In my data stack I put:

on mouseDown
put target
end mouseDown

Now when I click the button the answer dialog appears, and if I click “Yes”, the command window shows:

button “Yes” (or button “No” if “No” is clicked)

So as there is no other source of mouseDown, it must be generated by the answer dialog buttons . QED

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Answer function

Post by mwieder » Sat Nov 14, 2020 1:12 am

...and there's a simple fix for this. You wanna file the bug report or should I?

stam
Posts: 2679
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Answer function

Post by stam » Sat Nov 14, 2020 1:45 am

Hi Odysseus,

I could not replicate your problem (LiveCode Indy 9.6.1)

Just in case i've misunderstood your issue, the problem you describe is:
- Main stack has a mouseDown event, in this example puts the name of target
- Modal stack has other buttons - when they clicked they trigger the mouseDown even in the main stack, or if an answer dialog is shown, clicking on the buttons of the answer dialog triggers the mouseDown event in the main stack.

Here is a test project where the main stack has a mouseDown handler that puts the name of target.
Opening a substack as modal, there are two buttons, one with a mouseUp handler that answers "hello" with "yes" or "no", and one that does nothing.

No matter what button i click, the only time anything is put into the message box is when i click on the button in the main stack that opens the modal stack.

If I've understood correctly, this is the opposite of what you're observing?

If you are observing something else, or if your problem is a different one, perhaps share a simplified stack showing the issue?

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9823
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Answer function

Post by FourthWorld » Sat Nov 14, 2020 2:07 am

It's not the mainstack, it's a library. The global scope of the library allows it to catch any events but trapped elsewhere.

The more I think about it, the more it seems impractical for all IDE components and all third-party plugins to trap all possible messages just for edge cases like this. It's very rare to handle system messages in a library.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

stam
Posts: 2679
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Answer function

Post by stam » Sat Nov 14, 2020 2:11 am

Sorry Richard, i kinda skimmed most of this and just really paid attention to Odysseus' post, where there is no mention of libraries...
Thought i'd try to replicate the reported error but i couldn't... but that is only based on his example in this post.

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Answer function

Post by mwieder » Sat Nov 14, 2020 2:24 am

Richard- while I do somewhat agree with
it seems impractical for all IDE components
I don't think it's right that a modal dialog should leak a mouseDown message. It's a simple fix to the Answer dialog stack... it's already obviously got a mouseUp handler, so an empty mouseDown handler to match it neatly solves the problem. While this may well be considered an edge case, it's taken us three pages of comments here to figure out what's going on. AFAIK Answer dialogs will otherwise only respond to mouseUp messages.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9823
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Answer function

Post by FourthWorld » Sat Nov 14, 2020 2:56 am

If you feel limiting this to the ask and answer dialogs would be sufficient, that would be easy to remedy.

I can imagine many other unexpected anomalies with libraries that handle system messages, though, so I'm not sure those would be enough.

In the other hand, I've read nearly every post here and in the mailing list since their respective beginnings, and I've not seen this come up before.

LiveCode is very flexible. Handling messages globally comes with a certain responsibility. It's rare that folks do that at all, and rarer when done by those unfamiliar with the implications of that choice.

All that said, I see good arguments for both doing the work and for just adding a caveat in the docs. As long as I'm not doing the work I'll happily go along with whomever does. :)
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”