Entity
Entity is a primitive type in quake-c language. They are essentially a struct which come into existence with their own individual set of member variables.
Entities are the only collections of variables in quake-c.
In this quake-c snippet the 'self' entity's 'pain_finished' variable is set
self.pain_finished = time + 2;
Life Cycle
Some entities are created at level start and other entities are created afterwards.
Entities created after the start of the level are created via the 'spawn()' function:
Entities can be removed from the game with the built-in function remove(entity) or sometimes SUB_Remove
Engine Callbacks
Entities can get callbacks from the engine depending on how they are set up. At the start of the callback 'self' will be assigned to the current entity.
touch
touch is called when the physics engine has detected a collision between entities or the world and the entity. Important note: The physics engine may not call the touch callback when an entity and the entity's 'owner' collide.
think
Think is called on the first game tick after 'nexttime' becomes less than or equal to 'time'.
Entity Variables
New entity variables can be defined much as in 'defs.qc'
The code:
.string deathtype;
defines the floating point variable 'deathtype' which can be accessed as in the if-statement below:
if (targ.deathtype == "falling")
Since all entities regardless of whether they are a projectile or a lamp or a monster each have the same set of member-variables to store things in, it is easy to make use of nonsensical fields to store properties for new behavior and has the benefit of not changing the memory footprint of every other entity created in the game.
There doesn't appear to be a limit on the number of variables that can be attached to an entity.
New entity variables can be declared anywhere in the code.
Trivia
Even in the 2021 release there are a limited number of entities that can be created in a given game
Entities can cause excessive network traffic and slow the game dramatically
Each entity is created the same with all entity-defined variables attached