Skip to content

[Merged by Bors] - Add example for run conditions#7652

Closed
LiamGallagher737 wants to merge 7 commits intobevyengine:mainfrom
LiamGallagher737:main
Closed

[Merged by Bors] - Add example for run conditions#7652
LiamGallagher737 wants to merge 7 commits intobevyengine:mainfrom
LiamGallagher737:main

Conversation

@LiamGallagher737
Copy link
Copy Markdown
Member

@LiamGallagher737 LiamGallagher737 commented Feb 13, 2023

Added an example for run conditions. Fixes #7646 if we wait till #7605 is merged and include some of it features.

@github-actions
Copy link
Copy Markdown
Contributor

Welcome, new contributor!

Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨

@alice-i-cecile alice-i-cecile added A-ECS Entities, components, systems, and events C-Examples An addition or correction to our examples labels Feb 13, 2023
// this is useful for small, simple run conditions you don't need to reuse.
// All the normal rules still apply, all parameters must be read only except for local parameters
// In this case we will only run if the input counter resource exists and has changed but not just been added
.run_if(|res: Option<Res<InputCounter>>| {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I correct in thinking that once #7605 in merged we could do something like this?

.run_if(resource_exists::<InputCounter>())
.and_then(|counter: Res<InputCounter>| counter.is_changed() && !counter.is_added())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, precisely :) Interestingly, the short circuiting nature would make sure that the second run condition doesn't panic. That's nice.

Copy link
Copy Markdown
Member

@joseph-gio joseph-gio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall I'm happy with this, I just have a few grammar nitpicks.

@alice-i-cecile
Copy link
Copy Markdown
Member

bors r+

@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Feb 18, 2023
@bors
Copy link
Copy Markdown
Contributor

bors bot commented Feb 18, 2023

Timed out.

@alice-i-cecile
Copy link
Copy Markdown
Member

Github plz.

bors r+

bors bot pushed a commit that referenced this pull request Feb 18, 2023
Added an example for run conditions. Fixes #7646 if we wait till #7605 is merged and include some of it features.
@bors bors bot changed the title Add example for run conditions [Merged by Bors] - Add example for run conditions Feb 18, 2023
@bors bors bot closed this Feb 18, 2023
myreprise1 pushed a commit to myreprise1/bevy that referenced this pull request Feb 18, 2023
Added an example for run conditions. Fixes bevyengine#7646 if we wait till bevyengine#7605 is merged and include some of it features.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ECS Entities, components, systems, and events C-Examples An addition or correction to our examples S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add an example demonstrating run conditions

4 participants