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

Question: Is it possible to do nested for loops? #706

Open
dmitsuki opened this issue Aug 6, 2020 · 4 comments
Open

Question: Is it possible to do nested for loops? #706

dmitsuki opened this issue Aug 6, 2020 · 4 comments

Comments

@dmitsuki
Copy link

dmitsuki commented Aug 6, 2020

Is it possible to do nested for loops simply within system iterations? If I call join on a &mut component then try to iterate inside that component using join again, the borrow checker complains. What is the intended way to have every entity operate on every entity as an example, mutably.

@salpalvv
Copy link

salpalvv commented Aug 6, 2020

You can't mutably borrow twice. What are you trying to do? Perhaps it can be rewritten because this is, as you said, a borrow checker issue with your implementation and not specs-specific

@dmitsuki
Copy link
Author

dmitsuki commented Aug 6, 2020

I just want to do a n^2 component operation on some component. Would I have to iterate over entities instead and use get_mut then to make this work?

@salpalvv
Copy link

salpalvv commented Aug 6, 2020

There are many ways to do it and it's been answered a lot on stackoverflow depending on your situation, which you won't give details on. You can split the iterator, copy it and walk that, use interior mutability, or pass a message to another system and have that other system mutate it. Or just rewrite it to not have a nested loop. If it's for collision, you can use ncollide and just query the collision world.

@WaDelma
Copy link
Member

WaDelma commented Aug 9, 2020

Note that you can use Storage::get_mut to mutably get certain component for an entity.

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

No branches or pull requests

3 participants