API Reference › Reflect › Reflect.field
method

Reflect.field

Reflect.field(prop, name) -> int

Resolves a field name within property prop to its field id (index), or -1 if the property has no such field. Pair it with Reflect.get/Reflect.set to read or write that field.

Parameters

propa property id (from Reflect.prop)
namethe field name

Example

program Demo {
  property Health { hp: int = 0, max: int = 0 }
  model Unit { Health }
  entry {
    let H  = Reflect.prop("Health")
    let mx = Reflect.field(H, "max")
    print(mx)
  }
}
← All symbols