From 582b09be6645dd64242abc880693a2e99f6d59fc Mon Sep 17 00:00:00 2001 From: Ukendio Date: Sat, 11 May 2024 02:12:47 +0200 Subject: [PATCH] Update readme --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index af675da..6bb4607 100644 --- a/README.md +++ b/README.md @@ -45,9 +45,14 @@ world:set(opponent, Position, Vector3.new(0, 5, 3)) for playerId, playerPosition, health in world:query(Position, Health) do local totalDamage = 0 for opponentId, opponentPosition, damage in world:query(Position, Damage) do + if playerId == opponentId then + continue + end if (playerPosition - opponentPosition).Magnitude < 5 then totalDamage += damage end + -- We create a pair between the relation component `DamagedBy` and the entity id of the opponent. + -- This will allow us to specifically query for damage exerted by a specific opponent. world:set(playerId, ECS_PAIR(DamagedBy, opponentId), totalDamage) end end @@ -57,7 +62,7 @@ for playerId, health, inflicted in world:query(Health, ECS_PAIR(DamagedBy, oppon world:set(playerId, health - inflicted) end -assert(world:get(playerId, Health) == 79) +assert(world:get(player, Health) == 79) ``` 125 archetypes, 4 random components queried.