Skip to content

GetByIndex<T = Entity>(index: number)

GetByIndex<T = Entity>(index: number): T | null

  • indexnumber - the index of the entity to retrieve.

Description

The GetByIndex function is designed to get an entity by its index. It is a generalized function, which allows working with different types of entities.

Returned

  • T - the entity that matches the provided index.
  • null - if local hero is not exists.

Example

ts
let exampleScript: ScriptDescription = {};

exampleScript.OnScriptLoad = () => {
	let myHero = EntitySystem.GetByIndex<Hero>(EntitySystem.GetLocalHeroIndex());
	if(myHero) {
		console.log("My hero name - ", myHero.GetUnitName());
	} else {
		console.log("Local hero not found");
	}
}

RegisterScript(exampleScript, "Example script");