Blackboard Note

v4.0

Blackboard Notes

To receive updates from a Blackboard Note or a Blackboard Event, a script must implement IFollowBlackboard, or inherit from BlackboardFollower.

Blackboard Notes contain a "Topic" and "Subject", both strings, which are similar to the key in a Dictionary key/value pair. They also contain a selection of data types, including Game Module types like GameItemObject or GameStat.

The Blackboard module allows other objects to follow it, and receive a notification whenever a BlackboardNote is added or updated, and when a BlackboardEvent is sent. Followers should check to see if the topic and subject are what they are looking for, and if so, handle the new data.

// BlackboardNote.cs
public string name; // Mostly useful for the inspector
public string topic; // The broad topic. Examples could be "Kills" or "Dungeon Doors"
public string subject; // The specific subject. Such as "Goblins" or "Crypt" 
public object value;

// General types
public float valueFloat; 
public int valueInt;
public string valueString; 
public bool valueBool;
public GameObject valueGameObject;
        
// Game Module types
public GameStat valueGameStat;
public GameItemObject valueGameItemObject;
public GameItemAttribute valueGameItemAttribute;
public GameCondition valueGameCondition;
public GameQuest valueGameQuest;
public GameLootBox valueGameLootBox;
        
// Game Lists
public GameStatList valueGameStatList;
public GameItemObjectList valueGameItemObjectList;
public GameConditionList valueGameConditionList;
public GameQuestList valueGameQuestList;

You can Add() Blackboard Notes, though it may be more ideal to Update() the note in most cases, as this will automtically add the note if it does not yet exist.

// Update a note value, or add it if it doesn't exist
blackboard.UpdateNote("Party", "Distance Travelled", DistanceTravelled, true, true);

// Update a note without sending a notification to followers
blackboard.UpdateNote("Party", "Distance Travelled", DistanceTravelled, true, false);

// Get a note from the Blackboard
blackboard.TryGet(topic, subject, out BlackboardNote note);
Debug.Log($"The int value is {note.valueInt}.");

// Example of receiving a change from the blackboard
public override void ReceiveChange(BlackboardNote blackboardNote)
{
     // We only care about our topic / subject
     if (blackboardNote.topic != topicWeCareAbout 
          || blackboardNote.subject != subjectWeCareAbout) return;

     DoSomethingWith(blackboardNote);
}

Last updated