User interface question

Hi,

In this game:

For every ball that lands in the basket, I would like the score to increase by 1, with occasional increases of 2 or 3.

see the code:

Why this happens?

thanks

My pruposal

Assign a boolean object variable to the ball “InBasket”.
When you create object ball, force FALSE as variable value

condition:
ball is colliding to basket
and
“InBasket” = FALSE

action
“InBasket” = TRUE
playscore add 1
Score = “score:” + VariableString(Playscore)

Thanks,
J

Unfortunately, your proposal isn’t working!

I tested this code but still have problem:

You use an image of the actual basket or hidden sprite with a custom default mask in the shape of the can.
image

The red Zone wouldn’t have the physics behavior. The first event would be needed on the off chance that the first ball could bounce off the edge or something. The 2nd line only updates if there’s a collision. The NOT condition is used in the first event because an inverted collision condition would trigger if there weren’t balls in the can even if there were balls in the can. You need to check if there are none.

Physics collisions with the can would only trigger when the ball was in collision with the basket. The balls on top of other balls wouldn’t be counted. The balls will go thru the red box but still trigger the default collision.

Also, if you’re counting the number of shot balls, you can increase the variable in the same event that adds a new ball. By counting the objects in collision, you wouldn’t need the for each object event.

I wrote it.
Test my code, I hope it will help you.

I’ll delete the share into a mounth.

Thanks,
J

“This point is quite tricky, and I hadn’t considered it before.”

But the point that confuses me is that the ball has physics behavior and you need to consider the physics collision.

But you used a regular collision!

Can you explain this?

Do you mean we have two balls on top of each other and one has physics behavior and the other doesn’t?

Thank you for your assistance, but it seems you overlooked this point:d this point:

Physics collisions with the can would only trigger when the ball was in collision with the basket. The balls on top of other balls wouldn’t be counted. The balls will go thru the red box but still trigger the default collision.

“Please consider this text and let me know your thoughts.”

The normal collision and default mask don’t stop working when behaviors are added but different needs require different events.

If both objects have the physics behavior then you would use the physics collision condition. You could still use the default collision behavior but because they use different masks the physics mask might keep the objects from getting close enough to trigger the basic collision.

So, if the test object or zone doesn’t have the physics behavior then the ball will go through it instead of bouncing off it. That would allow the basic collision to work.

Thanks, now it works.
“But what does ‘invert condition’ mean?”

1 Like

Invert refers to when you invert a condition either through a switch or the popup menu. Basically changing in collision to not in collision.

Do you have something in mind like:

if !(ball.collide(zone)=0

I posted this earlier. IDK the Javascript version should you be using Javascript unless that’s just a way to display it.

The NOT (invert) condition inverts the result while inverting the condition inverts the condition. They’re similar but different. I can try to explain further or find a post where I previously discussed it.

Couldn’t we instead of using the above line, write:

if (Ball is in collision with zone) change the text to 1

invert condition from Microsoft:

Microsoft Copilot:
In GDevelop, the “invert condition” feature allows you to negate the result of a condition. However, there are some nuances to be aware of when using it. Let’s dive into the details:

Inverting Conditions:
When you invert a condition, it essentially flips the result. For example, if the original condition evaluates to true, the inverted condition will evaluate to false, and vice versa.
You can use the “invert condition” feature in various scenarios, such as checking if the mouse cursor is not on an object or if a certain variable is not equal to a specific value.
Groups and Instances:
When working with object groups, the behavior of inverted conditions can be a bit tricky.
Let’s say you have an object group (e.g., buttons in the UI), and you want something to happen when the mouse cursor is not on this group and the left mouse button is pressed.
If you use the “invert condition” on the cursor being on the object group, it might not behave as expected. The reason is that the engine considers instances of objects, not just the group itself.
The engine checks if all instances in the group meet the condition. If there’s at least one instance that meets the condition (e.g., the cursor is on one of the buttons), the inverted condition will still evaluate to true.
To work around this, consider using a “For Each” loop to iterate through all instances in the group and check the condition individually.
Example:
Let’s say you have a group of buttons, and you want an action to occur when the mouse cursor is not on any button and the left mouse button is pressed.
Instead of directly inverting the condition for the entire group, you can use a loop to check each button individually:
For each button in ButtonGroup:
If cursor is on button:
Stop loop
// If the loop completes without stopping, execute the action

This way, the condition will consider all instances in the group and return true only if none of them meet the condition.
Remember that GDevelop’s engine works with instances, so understanding how conditions apply to individual instances within a group is crucial. If you encounter unexpected behavior, consider using loops or rethinking your condition logic123. Happy game development! :rocket::video_game:

Yes, you could use for each object and test each object separately but using a NOT event and regular collision is simplier although in this case you probably could set the text or count to 0 without a condition and if in collision change the text or a variable.

Depending on what you’re an action being triggered on each frame is more efficient than a condition being triggered on each frame. It’s usually best to use conditions but there are always exceptions.

This would also work.

The Collision between objects condition picks the objects and returns true

[Inverted] Collision between objects picks the objects not in collision and returns true

If you put a collision inside a NOT condition then it inverts the result.

So, if there’s a collision it inverts the true and makes it false.

If there isn’t a collision then it would normally not trigger the action but the NOT condition inverts it and makes it true.

It’s subtle but different.

1 Like