Blackboard

From MyGamingTalk
Jump to navigation Jump to search
Script Reference Blackboard Functions

The blackboard is basically a global database that can be used to store generic data records. Items on the blackboard are made up of several common properties, and any number of additional user properties that can be passed as part of the table.

These properties are required for every record posted.

  • Owner - The owner id
  • Target - The target id
  • Duration - How long does it take for the record to expire
  • DeleteOnExpire - Whether the record is automatically deleted when it expires

What each property means is normally dependent on the type of blackboard record. The Owner is typically the game id of the bot, the target is normally an id that can be mapped to another object, such as a MapGoal serial number. The other properties control the records lifetime.

Blackboard Functions

MakeKey

Makes a numeric blackboard item key. Normally you will inject this value into the global BB table with the rest of the blackboard keys.

Parameters: none

Returns: numeric key.

Example:

 BB.MYNEWKEY = Blackboard.MakeKey();

PostRecord

Posts a record to the blackboard, keyed to a certain type, and storing arbitrary values.

Parameters: (blackboard key, table)

Returns: none

Example:

 mytable = 
 {
     Owner = b.GetGameId(),
     Target = 100,
     Duration = 10,
     DeleteOnExpire = true,

     someinfo = 10,
     someinfo2 = 20,
 };
 Blackboard.PostRecord(BB.MYNEWKEY, mytable);

GetRecords

Retrieves all records matching a type from global Blackboard

Parameters: (blackboard key)

Returns: table of all blackboard records, null if non exist.

Example:

 records = Blackboard.GetRecords(BB.MYNEWKEY);
 if(records)
 {
      foreach ( i and rcd in records )
      {
          print(rcd.someinfo);
          print(rcd.someinfo2);
      }
 }

GetNumRecords

Retrieves the number of records of a given type.

Parameters: (blackboard key)

Returns: number of records that exist of this type.

Example:

 numrecords = Blackboard.GetNumRecords(BB.MYNEWKEY);

RecordExistsOwner

Checks if a record exists for a certain key that matches a given owner id.

Parameters: (blackboard key, owner id #)

Returns: number of records that exist of this type.

Example:

 if(Blackboard.RecordExistsOwner(BB.MYNEWKEY, b.GetGameId())
 {
 }

RecordExistsTarget

Checks if a record exists for a certain key that matches a given target id.

Parameters: (blackboard key, target id #)

Returns: number of records that exist of this type.

Example:

 if(Blackboard.RecordExistsTarget(BB.MYNEWKEY, mapgoal.GetSerialNum())
 {
 }

RemoveByPoster

Removes all records of a given type by the given owner id.

Parameters: (owner id #) - If key type is left off, removes ALL records

Parameters: (owner id #, blackboard key type to remove)

Returns: number of records removed

Example:

 // remove just my record type from this owner
 numremoved1 = Blackboard.RemoveByPoster(b.GetGameId(), BB.MYNEWKEY);
 // remove all records of all types for this owner
 numremoved2 = Blackboard.RemoveByPoster(b.GetGameId());

RemoveByTarget

Removes all records of a given type by the given target id.

Parameters: (target id #) - If key type is left off, removes ALL records

Parameters: (target id #, blackboard key type to remove)

Returns: number of records removed

Example:

 // remove just my record type from this owner
 numremoved1 = Blackboard.RemoveByTarget(b.GetGameId(), BB.MYNEWKEY);
 // remove all records of all types for this owner
 numremoved2 = Blackboard.RemoveByTarget(b.GetGameId());

PrintBlackboard

Prints the global blackboard to the in game console.

Parameters: () - if key left off, prints records of ALL types.

Parameters: (blackboard key) - only print records of this type.

Returns: none

Example:

 Blackboard.PrintBlackboard();
 Blackboard.PrintBlackboard(BB.MYNEWKEY);