add_named_entity_listener - ryzom/ryzomcore GitHub Wiki


title: Add Named Entity Listener description: published: true date: 2023-03-12T16:42:17.153Z tags: editor: markdown dateCreated: 2023-03-12T16:42:13.941Z

addNamedEntityListener

The addNamedEntityListener native AI script function associates a listener with a named entity property. Whenever that field changes, the specified user event is triggered or a script function is called. Valid property names are:

  • state
  • param1
  • param2

Name of the entity cannot be listened, because it cannot change. Several listeners (even with the same parameters) can be associated to each property.

Syntax

()addNamedEntityListener(name: s, prop: s, event: f) // addNamedEntityListener_ssf_
()addNamedEntityListener(name: s, prop: s, cbFunc: s) // addNamedEntityListener_sss_

Arguments

  • name (string): The name of the named entity to listen to.
  • prop (string): The property of the named entity to listen to.

()addNamedEntityListener(s, s, f)

  • event (float): The user event to trigger when the named entity property changes.

()addNamedEntityListener(s, s, s)

  • cbFunc (string): The name of the script function to call when the named entity property changes.

Example

Trigger a user event

()addNamedEntityListener("Invasion", "state", 6); 

This example code associates a listener with the named entity "Invasion" and the property "state". Whenever the "state" property of the "Invasion" named entity changes, user event 6 will be triggered.

Call a script function

()addNamedEntityListener("Invasion", "state", "onStateChange"); 

This example code associates a listener with the named entity "Invasion" and the property "state". Whenever the "state" property of the "Invasion" named entity changes, the script function "onStateChange" will be called.

⚠️ **GitHub.com Fallback** ⚠️