API Reference › Entities & the ECS › world_get
function

world_get

world_get(target, property, field) -> int

world_get reads a single field of a model instance entirely by numeric id, returning its value as an int. It is the id-based counterpart to the ordinary position.column field access that queries give you — used when the property is not known at compile time, as in a mod or a generic tool. You supply the target instance (an entity), the property id (from world_prop_id), and the field id (from world_field_id); the result is the stored value. Pair it with world_set to write. Reading a field of an instance that lacks the property is not meaningful, so guard with world_has first if unsure.

Parameters

targetthe model instance to read from, an entity handle
propertythe property id, from world_prop_id
fieldthe field id within that property, from world_field_id

Example

program ReadField {
  property Position { column: int = 0, row: int = 0 }
  model Player { Position }

  handler Boot phase Start {
    spawn Hero { Position { column: 7, row: 2 } }
  }

  handler Inspect phase Update {
    let position_property = world_prop_id("Position")
    let column_field = world_field_id(position_property, "column")
    for (position) in query [Position, {Player}] {
      let value = world_get(self(), position_property, column_field)
      Screen.status(string(value))
    }
  }
}
← All symbols