How To Build Chatbots

on The Personality Forge
Chapters
Chapter 13: Conditional Responses

You have a great deal of control over when Responses will come up. They can be chosen or not depending on the time, the date, the content of memories, the Bot's feelings towards a person, and more. This is all done by AIScript in Responses.

Time-Based Responses

These are called "chrono statements".

TIME-BASED RESPONSES

Where: Responses

AIScript: chrono: hour(time-time);

Example: chrono: hour(13:00-18:00);

What It Does: This Response will only come up during the given range of hours. Hours must be in 24-hour format between 0:00 (midnight) and 23:59 (11:59 PM). For example, 6 PM would be 18:00.

WEEKDAY-BASED RESPONSES

AIScript: chrono: week(MTWRFSU);

Example: chrono: week(MTWRF);

What It Does: This response will only come up on the given days of the week. M=Monday, T=Tuesday, W=Wednesday, R=Thursday, F=Friday, S=Saturday, U=Sunday. In the above example, the Response will only come up on weekdays.

DATE-BASED RESPONSES

AIScript: chrono: day(day-day);

Example: chrono: day(2); Example: chrono: day(15-25);

What It Does: This response will only come up on the given date or range of dates in the month.

MONTH-BASED RESPONSES

AIScript: chrono: month(month-month);

Example: chrono: month(6); Example: chrono: month(11-12);

What It Does: This response will only come up on the given month or range of months.

NOTE: The date and time used is that person hosting that conversation's local time, if it can be determined. If not, the default is US Eastern Time, currently: Saturday, April 20, 2024 6:13 AM.

Combining Times and Dates

Limiting Dates

When you combine multiple time and date statements into one "chrono:" statement, then ALL of the conditions must be true for the Response to come up.

AIScript: chrono: timedate timedate;

Example: chrono: hour(13:00-18:00) week(MTWRF);
Example: chrono: day(20-24) month(12);

What It Does: In the first example, the Response will only come up between 1PM and 6 PM on a weekday. In the second example, the Response will only come up on Dec 20 - Dec 24.

Expanding Dates

When you list multiple time and date statements, each with their own "chrono:" tag, then only ONE of them must be true for the Response to come up.

AIScript: chrono: timedates; chrono: timedates;

Example: chrono: hour(22:00-23:59); chrono: hour(0:00-4:00);
Example: chrono: hour(13:00-18:00) week(MTWRF); chrono: hour(20:00-23:00) week(SU);

What It Does: In the first example, the Response will come up between 10 PM and 4 AM. In the second example, the Response will come up between 1 PM and 6 PM on a weekday OR 8 PM and 11 PM on a weekend.

Chrono Weighting

What if you have an #engage Response for a specific day of the year? The chances of it randomly coming up on that day seem very small. Worry not! The AI Engine uses a weighting system to increase the chance of a time-and-date-based Response being selected relative to the shortness of the time window. A single-day Response will have a much higher chance of being selected, while a Response with a 4-month window will get a very small boost.

Memory-Based Reponses

The AI Engine will automatically check each Response to make sure the proper memories exist before selecting one. Use this AIScript ONLY if you want a statement that doesnt use a particular memory within it to be dependent on its existence.

MEMORY-BASED RESPONSES

Where: Responses

AIScript: if (mem-memoryname) is "memoryvalue";
AIScript: if (self-memoryname) is "memoryvalue";

Example: if (mem-likes-doing) is "swimming";
Example: if (self-is-hungry) is "yes";

What It Does: The Response will only come up when the given memory has the given memoryvalue. If there are multiple stored memories of that type, only one has to be the given memoryvalue.


AIScript: if (mem-memoryname) is not "memoryvalue";
AIScript: if (self-memoryname) is not "memoryvalue";

Example: if (mem-likes-doing) is not "swimming";
Example: if (self-activity) is not "sleeping";

What It Does: The Response will only come up when the given memory does not have the given memoryvalue stored. If there are multiple stored memories of that type, none can be the given memoryvalue.


AIScript: if (mem-#-memoryname) > number;
AIScript: if (self-#-memoryname) < number;
AIScript: if (mem-#-memoryname) between number and number;

Option What It Does
= equal to
!= not equal to
> greater than
>= greater than or equal to
< less than
<= less than or equal to
Example: if (mem-#-pets) > 3;
Example: if (self-#-mood) between 2 and 5;
Example: if (mem-#-chances) >= 1;

What It Does: The Response will only come up when the numerical memory meets the given conditions.


AIScript: if (mem-memoryname) exists;
AIScript: if (self-memoryname) exists;

Example: if (mem-nickname) exists;
Example: if (self-last-action) exists;

What It Does: The Response will only come up if something is stored for the given memory.


AIScript: if (mem-memoryname) does not exist;
AIScript: if (self-memoryname) does not exist;

Example: if (mem-nickname) does not exist;
Example: if (self-last-action) does not exist;

What It Does: The Response will only come up when the given memory does not exist.

NOTE: Remember that the AI Engine will automatically check to make sure the proper memories exist before selecting a Response that uses them. Only use "exists" and "does not exist" if the memory you're checking isn't in the Response.

More Conditional Reponses
EMOTION-BASED RESPONSES

Where: Responses

AIScript: if emotion > number;
AIScript: if emotion between number and number;

Option What It Does
= equal to
!= not equal to
> greater than
>= greater than or equal to
< less than
<= less than or equal to
Example: if emotion > 3;
Example: if emotion < 0;
Example: if emotion >= 2;
Example: if emotion <= -3;
Example: if emotion between -2 and 2;

What It Does: The Response will come up only if your Bot's current emotion is within the range of the statement. The range of emotionvalue is from -5 to 5.

Alternate: emo can be used instead of emotion

You can also set the emotional range a Response works for by clicking "more" to the right of any Response when adding or editing them in the Language Center.

GENDER-BASED RESPONSES

Where: Responses

AIScript: if gender;

Example: if male;
Example: if female;

What It Does: The Response will only come up if the person is the given gender.

BE AWARE: When using Conditional AIScript, you are responsible for making sure there is at least one Response that will work in every situation. If you make a mistake and there are no valid Responses in a given situation, then the bot will say: "Sorry, there are no valid Responses for me to choose from."

SAY ONCE

This AIScript means your Bot will only say the Response to a given person once. This is useful for Responses whose answer does not change, such as asking "Are you a guy or a girl?" Asking that several times would not make sense. You should use "once" only rarely. You'll want to be writing Responses that will work in lots of situations and don't come across odd if said more than once.

Where: Responses

AIScript: once;

What It Does: The Response will only ever come up once per person.