11. Memorizing Name

The more you call their name, the better they feel.

The Problem

Compare the two dialogs below.

  • Log 1
    • Where are you from?
    • I'm from New York.
  • Log 2
    • Where are you from, Jack?
    • I'm from New York.

The dialog 2 is obviously better because the Tutor mentions the name of student but how we could do that?

In the previous session of this tutorial, we captures name from Input with * and returns it through <s/>. Can we store the name and then use it anytime anywhere as we want?

The Solution

You may use <u/> element to store anything you capture with <s/> and then returns it later. Check BrainXML Reference for more information on u element. The below are additional examples demonstrating how you may capture, memorize, and retrieve the students' name.

Example 1. Capturing name

  • Cell 1
    • My name is *
    • <strong/>what is your name
    • Nice to meet you, <s/>!

Example 2. Capturing and memorizing name

  • Cell 2
    • My name is *
    • <strong/>what is your name
    • Nice to meet you, <u>name=<s/></u>!

Alternatively, we may put the <u/> element in <think/>.

  • Cell 3
    • My name is *
    • <strong/>what is your name
    • Nice to meet you, <s/>!

Once Cell 2 or 3 is executed, the name is stored in the "name" property of system user object. You can then refer the use with <u>name</u> element.

  • Cell 3
    • Do you remember my name?
    • Sure, you told me you're <u>name</u>.
    • My name is Jack.
    • Nice to meet you, Jack!
    • ...
    • Do you remember my name?.
    • Sure, you told me you're Jack.

You can of course use <u> element to store and return any other data such as gender, age or location.

To answer the questions you might have:

  • Q: Will names mix up if there are many users?
  • A: No, never. BrainShop maintains an object for each user.
  • Q: Where and how the user object is stored or retrieved?
  • A: BrainShop takes care of that so you don't have to. You can focus yourself on building your own application without worrying about processing the data.
  • Q: Is the user object permanent?
  • A: Nearly permanent but we would clear the user object if the user is inactive for a very long time, saying a year.

Things to Keep in Mind

  • Use <u/> element to store/return user data such as name, gender, or age.