Skip to content

Create SocialEvents Using YAML Files

Shi Johnson-Bey edited this page Feb 28, 2024 · 4 revisions

How to create SocialEvents using YAML files

Specifying social events using YAML files is recommended for folks who might want to open their games for data-file modding. Also, it is an excellent way to specify all your events in one place that's easy to read. If you want to better familiarize yourself with YAML, the following page has been helpful: https://quickref.me/yaml.

  1. Right-click in the Project window and select Create > TDRS > Social Events YAML.
  2. Name the file whatever you wish
  3. This file expects social events to be supplied in a list with data fields similar to scriptable object versions. Each of the fields is described below.
  4. Remove the placeholder content and add your social events to the file
  5. Add a new SocialEventsYamlFileLoader component to the same GameObject as the SocialEngineController.
  6. Add the YAML file to the Social Event Yaml Files list on your SocialEventsYamlFileLoader instance.
  7. Try dispatching the event with some characters.
    • The sample code in the repo implements a MockSocialEventCreator (located in Assets/TDRS_Demo/Scripts/). This class allows you to specify an event type and a list of characters to bind to the event roles (in order).

Social Event YAML Object Fields

Important

Field names are case-sensitive

  • name: (required) The name of the event (used when specifying which event to dispatch)
  • roles: (optional) The names of roles of characters who are involved in the social event
  • description: (optional) A string description describing the social event.
    • This string uses a [role_name] template syntax that will substitute role names with the UIDs of the agents bound to those roles. For example, a description of [group_a] ended their feud with [group_b], will expand to montagues ended their feud with capulets assuming that agents with UIDs montagues and capulets were bound to roles group_a and group_b, respectively.
  • responses: This is where you specify how agents should react to this event. Each entry corresponds to a different response. Agents can respond to the same event multiple times, assuming they pass the preconditions for multiple response entries.
    • preconditions: (optional) These are RePraxis query statements to run against TDRS' database. Any variables bound with the query can be used within the effect functions.
    • effects: Effect functions to trigger when dispatching this event. You can read more about effect functions on the Social Events Page.
    • description: (optional) A response-specific description. Both even role names and precondition variable names are eligible for substitution using the square bracket syntax.

Sample YAML

- name: Betrayal
  roles:
    - "?betrayer"
    - "?victim"
  description: "[betrayer] betrayed [victim]."
  responses:
    - effects:
        - DecreaseRelationshipStat ?victim ?betrayer Friendship 10 5
        - RemoveRelationshipTrait ?victim ?betrayer friend
    - preconditions:
        - ?victim.relationships.?victim_friend.traits.friend
        - neq ?victim_friend ?betrayer
      effects:
        - DecreaseRelationshipStat ?victim_friend ?betrayer Friendship 5 6
    - preconditions:
        - ?victim.relationships.?victim_family.traits.family
        - neq ?victim_family ?betrayer
      effects:
        - AddRelationshipTrait ?victim_family ?betrayer angry_at 10

- name: BecomeFriends
  roles:
    - "?character_a"
    - "?character_b"
  description: "[character_a] and [character_b] became friends."
  responses:
    - effects:
        - AddRelationshipTrait ?character_a ?character_b friend
        - AddRelationshipTrait ?character_b ?character_a friend