SetInterval or WaitEvent(OnMouseUp) happens first?

Discuss any general programming issues here
Post Reply
Bugala
Posts: 919
Joined: Sun Feb 14, 2010 7:11 pm

SetInterval or WaitEvent(OnMouseUp) happens first?

Post by Bugala »

I have here a situation due to bad coding that I should have took into consideration already earlier.

Thing is, I have set this interval that keeps checking if LeftMouse is down. If it is not, then it cancels the situation.

At same time I have OnMouseUp event on a button that as long as situation is not cancelled, thing will happen.


Therefore my question is, When I release the Left Mouse button on top of that button, which happens first:

1. OnMouseUp happens first, then the setinterval check on if mouseis not down happens and cancels the situation.

2. SetInterval happens first, check it the left mouse is not down, and then cancels the event, at which point OnMouseUp event on that button doesnt do anything anymore since the situation got cancelled.

3. There is no way to say which happens first.


In addition, if answer is 1 or 2, then is this behavior always the same and will this behavior also stay from Hollywood version to next?


My own guess is that the answer is number 3, in which case I will probably make a sort of a hack for this situation.

User avatar
airsoftsoftwair
Posts: 4320
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: SetInterval or WaitEvent(OnMouseUp) happens first?

Post by airsoftsoftwair »

Bugala wrote:
Mon Mar 23, 2020 11:05 am
I have here a situation due to bad coding that I should have took into consideration already earlier.

Thing is, I have set this interval that keeps checking if LeftMouse is down. If it is not, then it cancels the situation.

At same time I have OnMouseUp event on a button that as long as situation is not cancelled, thing will happen.


Therefore my question is, When I release the Left Mouse button on top of that button, which happens first:

1. OnMouseUp happens first, then the setinterval check on if mouseis not down happens and cancels the situation.

2. SetInterval happens first, check it the left mouse is not down, and then cancels the event, at which point OnMouseUp event on that button doesnt do anything anymore since the situation got cancelled.

3. There is no way to say which happens first.


In addition, if answer is 1 or 2, then is this behavior always the same and will this behavior also stay from Hollywood version to next?
No, there is no guarantee in what order events are executed when they come in at the same time.

Bugala
Posts: 919
Joined: Sun Feb 14, 2010 7:11 pm

Re: SetInterval or WaitEvent(OnMouseUp) happens first?

Post by Bugala »

Made sort of hack to get around it. Next time I will be wiser and take that into consideration beforehand.

Post Reply