- Output field: Returns a custom user property, assign a custom user property with value, or execute a custom user method defined.
<user>property</user>
<user>property = expression</user>
<user>property ++</user>
<user>property --</user>
<user>method(args)</user>
Description
The user element works exactly same as "u" element except it handles custom user object.
This element loads the user object, executes a piece of custom JavaScript code, and returns the results. It is the only way to execute the custom BrainJS codes in Output field, with BrainXML. The specific codes to execute depend on what parameter is provided.
Parameters
property
Returns the value of JS code "user.property," which is defined under Properties, Codes tab.
property = expression
Calculates the BrainXML expression right to the equation mark; set the value of user.property as the result, in other words, execute JS code "user.property = result;"; and finally return the result.
property ++
Increases the value of property by 1 and returns the result. This only works for integer. If the property is not an integer, the property is returned as-is.
property --
decreases the value of property by 1 and returns the result. This only works for integer. If the property is not an integer, the property is returned as-is.
method(args)
Executes JS code "user.method(args);" and return the result. Depending on how the method is defined and used, the args can be empty or several comma separated arguments. The method must be pre-defined under Methods, Codes tab.
Examples
Example 1. Set and get a custom user property
- 1
- I like *
-
I like <user>like = <s/></user> too!
- 2
- What I like
-
You said you like <user>like</user>.
- I like pizza
- I like pizza too!
- ...
- What I like?
- You said you like pizza.
Example 2. Execute custom user method, without argument
- 1
- How long have we been chatting
-
About <user>getSessionMinutes()</user> minutes.
If you have defined user.getSessionTime() under Methods, Codes tab, the cells will work as below.
- How long have we been chatting?
- About 30 minutes.
Notes
- For built-in user property or method, check
<u/>
element.