Negative conditions with groups

Hi, I’ve had a problem for years of using negative conditions with groups. I’ve always managed a way to do things differently, but I’ve finally realised how to fix it. But is this problem expected behaviour, a bug or am I thinking about it wrong?

What I want:
An action to only happen if the cursor/touch is NOT on an object in a Group

If I do this:
Inverted :arrows_counterclockwise: The cursor/touch is on GroupName, it doesn’t work

But if I do this:
Not (Invert the logical result of these conditons):
The cursor/touch is on GroupName, it does work

Here is an example event.

Imagine i can ask 2 different questions to check your state

I wanna know if you are in toilet in your house

I wanna know are you not in toilet

INVERTING
Instead of checking are you in toilet
I can see you in kitchen so i know you are not in toilet

NOT
I can go to toilet and check are you in it
And return false statement

I am not good with english but one is checking it literally and other is checking outcome

Like another example

IS light switch on or off?

One method is to check if you see light or not
Where other is to check actual light switch state

It was confusing for me at first i still don’t get it
But bottom line it is a matter of what exactly you check

Where to cursor on object i was told
INVERTING was checking are you not on ALL of these objects at once
So you would need to be first of them them get off them

Where NOT will check if cursor is even touching any or something like that

Better someone come correct me

1 Like

This is expected behavior, yes.

Inverting a collision check (even not with a group, just something that has multiple instances) is relatively complex to explain, but know that generally it isn’t what you want unless you are applying actions to the instances themselves in a For Each event.

My understanding is that using the ‘Not’ condition basically is saying ‘not in collision with ALL’ letters, which is what you want.

The inverted condition is trying to do something like test the inversion of collision with objects, but since theres no object instances selected, there’s nothing to test against. (Whereas in a for each event, you have already selected an instance in the current loop, etc).

1 Like

Thank you very much to both of you, it’s starting to make sense.

Thinking out loud based on both explanations - the inverted condition would not filter the result correctly because my conditions only test for the object that the cursor is on and all the other objects are untested.

And just checking I’ve got it right, would it be any rather than all?

To be fair i gonna give you tip i always follow myself
There are many things in gdevelop i can deduce or understand just by reading about them
BUT i don’t need to know WHY i only need to know HOW

For example i never know do i need For Each Object event type or not
I only know if something is not working on its own then i need to try for each object

When do i need Pick all Instances?
I really do not care
If something is not working without it
I try to use it

That is all i need to know
And same exact logic for me applies to Inverting and NOT
I do not care why cause in the end it will only make me know
Where i still will need to use it only if something does not work by just inverting condition
So what’s the point of knowing if its always either A or B?

But that is only my personal TIP

NOW imagine this
You have enemy object
It have 2 animations
1st animation is enemy being blue
2nd is same exact animation but with enemy being red
Now you wanna always have 2 RED enemies on scene so what you do

Enemy animation = red
Enemy living on screen NOT EQUAL 1

Or

Enemy animation = red
INVERTED Enemy living on screen = 1

Should work right?
Well look these conditions are trying to find enemy that have animation red
But they can’t cause it does not exist so there is nothing to pick

Think of it like this if you wanna check if player killed all enemies in scene
You check if picked instances count = 0

BUT if there is no enemy on your scene it cannot pick any instances at all
So it cannot execute this event

Like you wanna set HP bar to player HP variable
BUT when player dies and you delete your player object
There is no object from which it can read variable to set HP bar width

So if you can die as player from HP being less than 0 then you are perfectly fine

BUT if you allow to kill player by idk touching spikes or lava
And you make it instant death
Just by deleting player without subtracting from HP var
HP bar will remain at its state it was when you killed player
CUASE even so HP variable upon deleting player object should become 0 since it does not exist
The fact that it does not exist anymore makes engine not being able to read anything from that object

Now remember that example with blue/red enemies? So you always have 2 red enemies on scene?
For me its big yellow plane
IDK why it needs to be this way
I just know i need to do it this way if just inverting condition don’t work

1 Like

A condition that picks objects is still picking those objects when inverted.

So the first one, “(inverted) cursor is on Letters”, should be read as “pick all Letters that the cursor is NOT touching”

In other words, if there are five Letters, and the cursor is on one of them, then the other four Letters are picked. If the cursor is not on any of them, then all five will be picked. In fact, the only way for this condition to be false (no objects picked) would be if all the Letters were stacked up so that the mouse cursor could be on ALL of them at the same time.

The second one is like this:

  • Pick all Letters that the cursor is touching
    → Is anything picked? Return FALSE (don’t do actions)
    → Is nothing picked? Return TRUE (do actions)

So as you can see, this is a very different result. The event only continues on to the actions if picking “fails” (which would be when the cursor is not on any of the objects)

1 Like