examples/cpp/game_mechanics/inventory_system/src/main.cpp
// Move items from one container to another
Move items from one container to another
Move items from one container to another
void transfer_items(flecs::entity dst, flecs::entity src) {
    std::cout << ">> Transfer items from " 
        << src.name() << " to " << dst.name() << "\n\n";
    dst.world().defer([&] {
        dst = get_container(dst); 
        src = get_container(src);
        for_each_item(src, [&](flecs::entity item) {
            transfer_item(dst, item);
        });
    });
}
void transfer_items ( flecs :: entity dst , flecs :: entity src ) { std :: cout << " " << src . name ( ) << " " << dst . name ( ) << " \n \n " ; dst . world ( ) . defer ( [ & ] { dst = get_container ( dst ) ; src = get_container ( src ) ; for_each_item ( src , [ & ] ( flecs :: entity item ) { transfer_item ( dst , item ) ; } ) ; } ) ; }
Move items from one container to another
Move items from one container to another
// Defer, because we're adding/removing components while we're iterating // Make sure to replace players with container