EntitySend

Family: Studio · 2 forms

What it does

Sends a message to every scene entity that matches an id, a name or a tag. Their scripts receive it through onMessage.

Syntax

1
EntitySend(entity string, message string) → integer
2
EntitySend(entity string, message string, dataJson string) → integer

Parameters

NameTypeIn formsMeaning
entitystringallThe id, name or tag of the receivers. Every matching entity gets the message.
messagestringallThe message name.
dataJsonstring2Optional data sent with the message, as JSON text. Text that is not valid JSON is sent as a plain string.

Every form returns

integer

The number of entities that received the message, 0 when none matches.

Good to know

  • When nothing matches, one warning is written to the console, once per name.

Example · generated

Form 1, the short one

DO  Print(EntitySend("value", "hello"))  Sync()LOOP

Form 2, with every argument

DO  Print(EntitySend("value", "hello", "{}"))  Sync()LOOP

EntitySend is called and its answer is printed every frame. The DO … LOOP is not decoration: a classic BASIC program ends the moment it runs out of lines, and Sync() is what draws the frame.

133 commands in Studio