examples/cpp/game_mechanics/inventory_system/src/main.cpp
// Find item in inventory of specified kind
Find item in inventory of specified kind
Find item in inventory of specified kind
flecs::entity find_item_w_kind(
    flecs::entity container, flecs::entity kind, bool active_required = false) 
{
    flecs::entity result;
    container = get_container(container);
    for_each_item(container, [&](flecs::entity item) {
        if (active_required) {
            if (!item.has<Active>()) {
                return;
            }
        }
        flecs::entity ik = item_kind(item);
        if (ik == kind) {
            result = item;
        }
    });
    return result;
}
flecs :: entity find_item_w_kind ( flecs :: entity container , flecs :: entity kind , bool active_required = false ) { flecs :: entity result ; container = get_container ( container ) ; for_each_item ( container , [ & ] ( flecs :: entity item ) { if ( active_required ) { if ( ! item . has < Active > ( ) ) { return ; } } flecs :: entity ik = item_kind ( item ) ; if ( ik == kind ) { result = item ; } } ) ; return result ; }
Find item in inventory of specified kind
Find item in inventory of specified kind
// Check if we should only return active items. This is useful when // searching for an item that needs to be equipped.