@@ -34,13 +34,13 @@ int main(int argc, char *argv[]) {
3434 ecs_entity_t e1 = ecs_new_id (ecs );
3535 ecs_set_pair (ecs , e1 , Requires , Gigawatts , {1.21 });
3636 const Requires * r = ecs_get_pair (ecs , e1 , Requires , Gigawatts );
37- printf ("requires: %f \n" , r -> amount );
37+ printf ("requires: %.2f \n" , r -> amount );
3838
3939 // The component can be either the first or second part of a pair:
4040 ecs_entity_t e2 = ecs_new_id (ecs );
4141 ecs_set_pair_second (ecs , e2 , Gigawatts , Requires , {1.21 });
4242 r = ecs_get_pair_second (ecs , e2 , Gigawatts , Requires );
43- printf ("requires: %f \n" , r -> amount );
43+ printf ("requires: %.2f \n" , r -> amount );
4444
4545 // Note that <Requires, Gigawatts> and <Gigawatts, Requires> are two
4646 // different pairs, and can be added to an entity at the same time.
@@ -50,7 +50,7 @@ int main(int argc, char *argv[]) {
5050 ecs_entity_t e3 = ecs_new_id (ecs );
5151 ecs_set_pair (ecs , e3 , Expires , ecs_id (Position ), {0.5 });
5252 const Expires * e = ecs_get_pair (ecs , e3 , Expires , ecs_id (Position ));
53- printf ("expires: %f \n" , e -> timeout );
53+ printf ("expires: %.1f \n" , e -> timeout );
5454
5555 // You can prevent a pair from assuming the type of a component by adding
5656 // the Tag property to a relationship:
@@ -84,12 +84,29 @@ int main(int argc, char *argv[]) {
8484 printf ("%s\n" , type_str );
8585 ecs_os_free (type_str );
8686
87+ // When querying for a relationship, provide both parts of the pair:
88+ ecs_query_t * q = ecs_query_init (ecs , & (ecs_query_desc_t ) {
89+ .filter .terms = {
90+ { .id = ecs_pair (ecs_id (Requires ), Gigawatts ) }
91+ }
92+ });
93+
94+ // When iterating, always use the pair type:
95+ ecs_iter_t it = ecs_query_iter (ecs , q );
96+ while (ecs_query_next (& it )) {
97+ r = ecs_term (& it , Requires , 1 );
98+ for (int i = 0 ; i < it .count ; i ++ ) {
99+ printf ("requires %.2f gigawatts\n" , r [i ].amount );
100+ }
101+ }
102+
87103 // Output:
88- // requires: 1.210000
89- // requires: 1.210000
90- // expires: 0.500000
104+ // requires: 1.21
105+ // requires: 1.21
106+ // expires: 0.5
91107 // Requires
92108 // Requires
93109 // Expires
94110 // 0
111+ // requires 1.21 gigawatts
95112}
0 commit comments