Download Tutorial C Files H Files

dg_entity_has_component

This function is used to get the index of a component in an entity.

Usage

int dg_entity_has_component(dg_entity_t *entity, char *name);

Example

int index = dg_entity_has_component(entity, "score");

Source code

int dg_entity_has_component(dg_entity_t *entity, char *name)
{
    dg_array_t *tmp = 0;
    int index = -1;

    if (!entity || !name)
        return -1;
    tmp = entity->components;
    while (tmp) {
        index++;
        if (!dg_strcmp(((dg_component_t *)(tmp->data))->name, name))
            return index;
        tmp = tmp->next;
    }
    return -1;
}