Why is my logic being executed many times per click?

I have the following simple logic:


However, it appears to be executed several times per click - the “visible” property flashes on and off, and sometimes the item toggles the visibility, and sometimes it doesn’t.

I have had this happen with a Python script too… whenever I press a button, it executes the appropriate code 3 or 4 times!

Would someone be so kind as to tell me what is going on?

It does not. If it would you would not see it.

Because there is exactly one frame rendered per frame (in lag situation it might be skipped).

lets see what you wrote:

A)
When

mouse left button pressed AND
mouse cursor over object AND
property click is False

Then

show object
play action forward
click = True

B)
When

mouse left button pressed AND
mouse cursor over object AND
property click is True

Then

hide object
play action forward
click = False

Lets skip what is the same condition in both situations: mouse click and mouse over
Lets skip what does not influence followup logic: playing action and showing/hiding

It remains:

If property click == True -> property click = False
If property click == False -> property click = True

Lets manually play it:

Property to check : Property set

True : False
False : True
True : False
False : True

So you get constant toggle between True and False.

That is what you described … that is what you get:

When mouse is over object and left button is clicked -> Toggle visibility on/off

… I thought that the click event would only be true once per click.

Yes, the logic should not be that hard :confused:

When Clicked () {
IF (visible)
{
text.hide
visible=false
}
if (!VISIBLE) {
text.show
visible=true
}
}

But I still don’t follow why it is toggling multiple times per click, sir - I can see it flashing, and again, sometimes it ends up changing state of visibility and sometimes it doesn’t when it is done flashing.

Does this have something to do with the number of frames in the animation? Like an odd or even # of frames would produce a different result?

Ahhh… by telling it to “skip”, I get the flashing to go much slower. So “Left Button” is less of an singular “event” and more of a “condition”. How do I get the logic to work such that it only fires ONCE for every click?

Now what you said makes sense! I had a bad assumption about what “triggers” Left Button.

60 times per second* or so

You can avoid this by using a timer, or states and a delay.

If timer equal zero—and---------Toggle property
If mouse over------/_____---------set property 30
If mouse clicked—/

If property timer interval min 1 max 999---------and-------add -1 to property timer

Remove the property “click” sensors.

Both mouse sensors measure the “click”. The “not click” is measured by them as well. To activate actuators on the inverse you connect them with a NAND (rather than an AND) controller.