Skip to main content

Group

Description:

  A record representing a group of entities in the ECS game systems.

Class Object: Group Class.

Inherits from: Object.

count

Type: Readonly Field.

Description:

  The number of entities in the group.

Signature:

const count: integer

first

Type: Readonly Field.

Description:

  The first entity in the group, or nil if the group is empty.

Signature:

const first: Entity

each

Type: Function.

Description:

  Calls a function for each entity in the group.

Signature:

each: function(self: Group, func: function(Entity): boolean): boolean

Parameters:

ParameterTypeDescription
funcfunctionThe function to call for each entity.Returning true inside the function to stop iteration.

Returns:

Return TypeDescription
booleanFalse if all entities were processed, True if the iteration was interrupted.

find

Type: Function.

Description:

  Finds the first entity in the group that satisfies a predicate function.

Signature:

find: function(self: Group, func: function(Entity): boolean): Entity

Parameters:

ParameterTypeDescription
funcfunctionThe predicate function to test each entity with.

Returns:

Return TypeDescription
EntityThe first entity that satisfies the predicate, or nil if no entity does.

watch

Type: Function.

Description:

  Watches the group for changes to its entities, calling a function whenever an entity is added or changed.

Signature:

watch: function(self: Group, func: function(Entity): boolean): Group

Parameters:

ParameterTypeDescription
funcfunctionThe function to call when an entity is added or changed. Returns true to stop watching.

Returns:

Return TypeDescription
GroupThe same group, for method chaining.