Skip to content

Commit

Permalink
Add calls to target() to relationship basics example
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed Oct 1, 2023
1 parent 2f099fc commit 7e05ef3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions examples/c/relationships/basics/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,13 @@ int main(int argc, char *argv[]) {
printf("Bob's type: [%s]\n", type_str);
ecs_os_free(type_str);

// Get first target of relationship
printf("Bob eats %s\n",
ecs_get_name(ecs, ecs_get_target(ecs, bob, Eats, 0)));

// Get second target of relationship
printf("Bob also eats %s\n",
ecs_get_name(ecs, ecs_get_target(ecs, bob, Eats, 1)));

return ecs_fini(ecs);
}
6 changes: 6 additions & 0 deletions examples/cpp/relationships/basics/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,10 @@ int main(int, char*[]) {
bob.each(flecs::Wildcard, pears, [](flecs::id id) {
std::cout << "Bob " << id.first().name() << " pears\n";
});

// Get first target of relationship
std::cout << "Bob eats " << bob.target<Eats>().name() << "\n";

// Get second target of relationship
std::cout << "Bob also eats " << bob.target<Eats>(1).name() << "\n";
}

0 comments on commit 7e05ef3

Please sign in to comment.