## Roxen Interactive RXML Help

## <set/> or <set></set>

Sets a variable in any scope that isn't read-only.

Before: &var.language;<br />
<set variable="var.language">Pike</set>
After: &var.language;<br /> |

Before: After: Pike |

### Attributes

**variable***variable=string**This attribute is required.*

The name of the variable to set.

**value***value=string*

The value the variable should have. This is an alternative to specifying the value in the content, and the content must be empty if this is used.

The difference is that the value always is parsed as text here. Even if a type is specified with the "type" attribute this is still parsed as text, and then converted to that type.

**from***from=string*

Get the value from this variable. The content must be empty if this is used.

**expr***expr=string*

An expression that gets evaluated to produce the value for the variable. The content must be empty if this is used.

Expression values can take any of the following forms:

*scope*.*var[*.*var...]*The value of the given RXML variable. This follows the usual RXML variable reference syntax, e.g. "." in a variable name is quoted as "..". The scope and variable names may only contain pike identifier chars, i.e. letters, numbers (except at the start of a scope name), and "_". An exception is that a

*var*may be a positive or negative integer.To reference an RXML variable that doesn't obey these restrictions, e.g. when a variable name contains "-", use the

`var()`or`index()`functions.Note that the variable is not written as an entity reference. I.e. it is written without the surrounding "&" and ";". Using e.g. "&form.x;" instead of "form.x" works most of the time, but it is more susceptible to parse errors if form.x contains funny things, and it is slower since Roxen cannot cache the compiled expression very well.

`49`A decimal integer.

`0xFE`,`0xfe`A hexadecimal integer is preceded by "0x".

`040`An octal integer is preceded by "0".

`0b10100110`A binary integer is preceded by "0b".

`1.43`,`1.6e-5`A floating point number contains "." and/or "E"/"e".

`"hello"`A string inside double quotes. C-style backslash escapes can be used in the string, e.g. a double quote can be included using \".

`(`*expr*)Parentheses can be used around an expression for grouping inside a larger expression.

Value conversion expressions:

`(int)`*expr*Casts a numeric or string expression (containing a formatted number on one of the formats above) to an integer.

`(float)`*expr*Casts a numeric or string expression (containing a formatted number on one of the formats above) to a floating point number.

`(string)`*expr*Casts a numeric or string expression to a string. If it is an integer then it is formatted as a decimal number. If it is a floating point number then it is formatted on the form

*[-]XX[.XX][e[-]XX]*.`INT(`,*expr*)`FLOAT(`,*expr*)`STRING(`*expr*)These functions cast their arguments to integer, float, or string, respectively. They behave like the cast operators above except that they do not generate any error if

*expr*cannot be cast successfully. Instead a zero number or an empty string is returned as appropriate. This is useful if*expr*is a value from the client that may be bogus.Note that values in the RXML form scope often are strings even though they may appear as (formatted) numbers. It is therefore a good idea to use the

`INT()`or`FLOAT()`functions on them before you do math.Expressions for numeric operands:

*expr1***expr2*Multiplication.

*expr1*/*expr2*Division.

*expr1*%*expr2*Modulo.

*expr1*+*expr2*Addition.

*expr1*-*expr2*Subtraction.

*expr1*<*expr2*Less than.

*expr1*>*expr2*Greater than.

*expr1*<=*expr2*Less than or equal.

*expr1*>=*expr2*Greater than or equal.

*expr1*&*expr2*Bitwise AND (integer operands only).

*expr1*^*expr2*Bitwise XOR (integer operands only).

*expr1*|*expr2*Bitwise OR (integer operands only).

`pow(`*expr1*,*expr2*)Returns the value

*expr1*raised to the power of*expr2*.`log(`*expr*)Returns the natural logarithm of the value

*expr*. To get the logarithm in another base, divide the result with`log(`.*base*)`abs(`*expr*)Returns the absolute value of

*expr*.`floor(`*expr*)Returns the closest integer value less than or equal to the value

*expr*.`ceil(`*expr*)Returns the closest integer value greater than or equal to the value

*expr*.`round(`*expr*)Returns the closest integer value to the value

*expr*.`max(`*expr*, ...)Returns the maximum value of the arguments.

`min(`*expr*, ...)Returns the minimum value of the arguments.

Expressions for string operands:

*expr***num*Returns

*expr*repeated*num*times.*expr1*/*expr2*Returns an array with

*expr1*split on*expr2*. E.g. the string "a,b,c" split on "," is an array with the three elements "a", "b", and "c".*expr1*+*expr2*Returns

*expr1*concatenated with*expr2*.*expr1*-*expr2*Returns

*expr1*without any occurrences of*expr2*.`var(`*expr*)Parses the string

*expr*as an RXML variable reference and returns its value. Useful e.g. if the immediateform cannot be used due to strange characters in the scope or variable names.*scope*.*var*`sizeof(`*expr*)Returns the number of characters in

*expr*.`search(`*expr1*,*expr2*)Returns the starting position of the first occurrence of the substring

*expr2*inside*expr1*, counting from 1, or 0 if*expr2*does not occur in*expr1*.`reverse(`*expr*)Returns the reverse of

*expr*.Expressions for array operands:

*expr***num*Returns

*expr*repeated*num*times.*expr1*+*expr2*Returns

*expr1*concatenated with*expr2*.*expr1*-*expr2*Returns

*expr1*without any of the elements in*expr2*.*expr1*&*expr2*Returns the elements that exist in both

*expr1*and*expr2*, ordered according to*expr1*.*expr1*^*expr2*Returns the elements that exist in either

*expr1*or*expr2*but not in both. The order is*expr1*followed by*expr2*.*expr1*|*expr2*Returns the elements that exist in either

*expr1*or*expr2*. The order is*expr1*followed by*expr2*. (The difference from*expr1*+*expr2*is that elements in*expr2*aren't repeated if they occur in*expr1*.)`sizeof(`*expr*)Returns the number of elements in

*expr*.`search(`*arr*,*expr*)Returns the position of the first occurrence of the element

*expr*inside the array*arr*, counting from 1, or 0 if*expr*does not exist in*arr*.`reverse(`*expr*)Returns the reverse of

*expr*.`uniq(`*expr*)Returns

*expr*with all duplicate elements removed. The order among the remaining elements is kept intact; it is always the first of several duplicate elements that is retained.Expressions for all types of operands:

`!`*expr*Logical negation: 1 (true) if

*expr*is the integer 0 (zero), otherwise 0 (false).*expr1*==*expr2*1 (true) if

*expr1*and*expr2*are the same, 0 (false) otherwise. Note that arrays may be different even though they contain the same sequence of elements.*expr1*!=*expr2*1 (true) if

*expr1*and*expr2*are different, 0 (false) otherwise. This is the inverse of the == operator.`equal(`*expr1*,*expr2*)1 (true) if

*expr1*and*expr2*are structurally equal, 0 (false) otherwise. As opposed to the == operator above, this returns 1 if two arrays contain the same sequence of elements.*expr1*&&*expr2*Nonzero (true) if both expressions are nonzero (true), 0 (false) otherwise. A true return value is actually the value of

*expr2*.*expr1*||*expr2*Nonzero (true) if either expression is nonzero (true), 0 (false) otherwise. A true return value is actually the value of the last true expression.

`index(`*scope*,*expr*, ...)Indexes the RXML scope specified by the string

*scope*with*expr*, and then continue to index the result successively with the remaining arguments. The indexing is done according to RXML rules, so e.g. the first index in an array is 1.

**type***type=type*

The type of the value. If the value is taken from the content then this is the context type while evaluating it. If "value", "from" or "expr" is used then the value is converted to this type. Defaults to "any".

Tip: The <value> tag is useful to construct nonstring values, such as arrays and mappings:

<set variable="var.x" type="array"> <value>alpha</value> <value>beta</value> </set> &var.x;Array result: ({"alpha", "beta"})

**split***split=string*

Split the value on this string to form an array which is set. The value gets converted to a string if it isn't one already.

<set variable="var.x" split=",">a,b,c</set> &var.x;Array result: ({"a", "b", "c"})