The Book of AI

How To Build Chatbots with The Personality Forge
Chapters
Chapter 10: 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. All of these are AIScript that you add to a Response.

Time-Based Responses

These are called "chrono statements".

TIME-BASED RESPONSES

Where: Responses

Statement: 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

Statement: chrono: hour(time-time);

Example: chrono: week(MTWRF);

What It Does: This response will only come up on the given weekdays. 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

Statement: 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

Statement: 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: If a person is involved in the conversation, the date and time used is that person's local time. All chatbots are located in Eastern Standard Time, so bot-to-bot chats will use that date and time.

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.

Statement: 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.

Statement: 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 xnone 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

Statement: if (mem-memoryname) exists;
Statement: 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.


Statement: if (mem-memoryname) does not exist;
Statement: 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.


Statement: if (mem-memoryname) is "memoryvalue";
Statement: 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.


Statement: if (mem-memoryname) is not "memoryvalue";
Statement: 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.

NOTE: Remember that the AI Engine will automatically check to make sure the proper memories exist before selecting a Response that uses them.

More Conditional Reponses
EMOTION-BASED RESPONSES

Where: Responses

Statement: if emotion > emotionvalue;
Statement: if emotion between emotionvalue and emotionvalue;

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

Statement: 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 "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

Statement: once;

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