All Entity objects can use their BrainManager to add brains to control behavior and functions.
BrainManager | All Entity objects can use their BrainManager to add brains to control behavior and functions. |
Brain Related | |
Add | |
Remove | |
GetBrainByName | |
SendToBrainByName | |
SendToBrainBase | |
AskBrainByName | |
State Related | |
SetStateByName | |
GetActiveStateName | |
InState | |
LastStateWas |
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.
brainName | A string containing the name of a valid brain that can be constructed, for example, Bob. |
initMsg | A string with any special information you want to send this brain. (can be a blank string) |
number Remove(string brainName)
brainName | The name of the brain you’d like to remove. |
How many brains were actually removed.
Brain GetBrainByName(string brainName)
This lets you see if an entity has a specific brain and returns it.
<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.
brainName | The 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.
nil SendToBrainByName(string brainName, string msg)
Allows you to send a command to a brain.
brainName | The name of the brain you’d like to communicate with. |
msg | The string of text you’d like to send. Different brains respond to different commands. |
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.
msg | The string of text you’d like to send. |
string AskBrainByName(string brainName, string msg)
Allows you to send a message to a brain and receive its reply.
brainName | The name of the brain you’d like to communicate with. |
msg | The string of text you’d like to send. Different brains respond to different commands. |
The brain returns a string of data in response to the request made.
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.
this:GetBrainManager():SetStateByName("Idle");
If the Entity is already in the desired state, the command is ignored.
stateName | A string containing the name of a valid state that can be activated, for example, Idle. |