Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can you pass Resources to run!()? #57

Open
PhaestusFox opened this issue Apr 23, 2023 · 2 comments
Open

can you pass Resources to run!()? #57

PhaestusFox opened this issue Apr 23, 2023 · 2 comments

Comments

@PhaestusFox
Copy link
Contributor

I want to have buttons that when clicked change the state of my game, is it possible to pass the NextState resource in so that I can change it when the button is pressed? I saw you can go the other way with the from!() and update a component from a resource but saw no way to update a resource from a component

<for tab in = Tab::iter()>
  <button c:tab with=tab on:press=run!(|tab: &Tab, next: mut ResMut<NextState>| next.set(*tab))>
    <img c:icon src=tab.icon()/>
  </button>
</for>
@jkb0o
Copy link
Owner

jkb0o commented Apr 25, 2023

Hello there! Right now it is not possible to pass resources into run! macro. The workaround is to use commands from the handler context, something like this:

<for tab in = Tab::iter()>
  <button c:tab with=tab on:press=run!(|ctx, tab: &Tab| {
    let tab = *tab;
    ctx.commands().add(|world: &mut World| world.resource_mut::<NextState>().set(tab))
  })>
    <img c:icon src=tab.icon()/>
  </button>
</for>

@jkb0o
Copy link
Owner

jkb0o commented Apr 25, 2023

But I'll check this one, it shouldn't be too difficult to bypass requested resources to run! handler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants