Create

Create creates a single entity with a given set of components.

func Create(worldCtx WorldContext, components ...metadata.Component) (EntityID, error)

Example

package system

func System(worldCtx cardinal.WorldContext) error {
    // ...
	
	// Create an entity with the Location and Health component.
	entityID, err := cardinal.Create(worldCtx,
		component.Location{},
		component.Health{},
	)
	if err != nil {
		return err
	}
	
	// ...
	
	return nil
}

Parameters

ParameterTypeDescription
worldCtxWorldContextA WorldContext object passed in to your system.
components…metadata.ComponentVariadic parameter for components to associate with the created entity.

Return Values

TypeDescription
EntityIDThe ID of the created entity.
errorAn error indicating any issues that occurred during the creation process.

CreateMany

CreateMany creates a specified amount of entities with a specified set of components.

func CreateMany(worldCtx WorldContext, num int, components ...metadata.Component) ([]EntityID, error)

Example

package system

func System(worldCtx cardinal.WorldContext) error {
    // ...
	
	// Create 10 entities with the Location and Health component.
	entityIDs, err := cardinal.CreateMany(worldCtx,
		10,
		component.Location{},
		component.Health{},
	)
	if err != nil {
		return err
	}
	
	// ...
	
	return nil
}

Parameters

ParameterTypeDescription
worldCtxWorldContextA WorldContext object passed in to your system.
numintThe number of entities to create.
components…metadata.ComponentVariadic parameter for components to associate with the created entities.

Return Values

TypeDescription
[]EntityIDA slice of EntityID representing the IDs of the created entities.
errorAn error indicating any issues that occurred during the creation process.

Remove

Remove removes a given entity from the World.

func Remove(worldCtx WorldContext, id EntityID) error

Example

package system

func System(worldCtx cardinal.WorldContext) error {
    // ...

	// Create an entity with the Location and Health component.
	entityID, err := cardinal.Create(worldCtx,
		component.Location{},
		component.Health{},
	)
	if err != nil {
		return err
	}

	// Remove the entity we just created
	err = cardinal.Remove(worldCtx, entityID)
	if err != nil {
		return err
	}
	
	// ...
	
	return nil
}

Parameters

ParameterTypeDescription
worldCtxWorldContextA WorldContext object passed in to your system.
identity.IDThe entity ID to be removed from the world.

Return Value

TypeDescription
errorAn error indicating any issues that occurred during the removal process.