BrainManager

All Entity objects can use their BrainManager to add brains to control behavior and functions.

Brain Related

Add

nil Add(string brainName, string initMsg)

Adds a new brain.

An entity can use many brains at once, most can play nicely and intelligently with eachother.

Some brains perform complex duties, like path-finding and movement, others very simple things, like shaking, bobbing, or fading out and deleting themselves.

Parameters

brainNameA string containing the name of a valid brain that can be constructed, for example, Bob.
initMsgA string with any special information you want to send this brain.  (can be a blank string)

Remove

number Remove(string brainName)

Parameters

brainNameThe name of the brain you’d like to remove.

Returns

How many brains were actually removed.

GetBrainByName

Brain GetBrainByName(string brainName)

This lets you see if an entity has a specific brain and returns it.

Note

<Brain> Is undocumented right now and only has a GetName() function, so this function is really only for tested to see if a certain brain exists or not at this time.

Parameters

brainNameThe name of the brain you’d like returned.

Returns: A <Brain> object or nil if no brain by this name exists in this entities BrainManager.

SendToBrainByName

nil SendToBrainByName(string brainName, string msg)

Allows you to send a command to a brain.

Parameters

brainNameThe name of the brain you’d like to communicate with.
msgThe string of text you’d like to send.  Different brains respond to different commands.

SendToBrainBase

nil SendToBrainBase(string msg)

Allows you to send a command to the “base” brain if one has been added.

Certain complex brains may register themselves as the “base brain”.  Right now only one, the StandardBase does this.

By registering as the “Base”, it’s letting the world and other brain’s know it can handle certain commands and services.

Parameters it understands

msgThe string of text you’d like to send.

AskBrainByName

string AskBrainByName(string brainName, string msg)

Allows you to send a message to a brain and receive its reply.

Parameters

brainNameThe name of the brain you’d like to communicate with.
msgThe string of text you’d like to send.  Different brains respond to different commands.

Returns

The brain returns a string of data in response to the request made.

State Related

SetStateByName

nil SetStateByName(string stateName)

Unlike brains, there can only be one state active at any time.

States such as walking, attacking, and idling allow visuals and AI related functions to all stay on the same page and an easy way to control entities.

Example of setting the state to Idle to stop an entity from moving, and to play the idle animation if it exists in his visual profile

this:GetBrainManager():SetStateByName("Idle");

Note

If the Entity is already in the desired state, the command is ignored.

Parameters

stateNameA string containing the name of a valid state that can be activated, for example, Idle.

GetActiveStateName

string GetActiveStateName()

Returns

The name of the active state.

InState

boolean InState(string stateName)

Parameters

stateNameThe name of the state you’d like to see if the entity is currently in.

Returns

True if active state matches the state name sent.

LastStateWas

boolean LastStateWas(string stateName)

Parameters

stateNameThe name of the state you’d like to see if the entity was last in, before the currently active state was set.

Returns

True if the last state that was active (before the current one was activated) matches the name sent.

The Entity object.
All Entity objects can use their BrainManager to add brains to control behavior and functions.
A brain for use with the BrainManager that causes its Entity’s visuals to “bob” up and down, without really moving the Entity.
A brain for use with the BrainManager that performs many generic functions such as movement and path-finding.
A state that causes an entity to stop and play his idle animation.