Mod:Creation Kit/Cast Reference

::= 'is'

Casting an expression from one type to another allows you to perform additional manipulations on the object, or hand it off to a function or property that expects a different type. The "is" operator checks to see if the expression to the left is the type requested. The check is strict for base types (bool, int, etc) but loose for object types (Form, Alias, etc). The various types of casts are listed below:

Cast to Boolean
Compiler auto-cast from: Anything

Anything in Papyrus can be cast to a boolean. The result that you get depends on the type of object that you are casting from, according to the following table:

Cast to Int
Compiler auto-cast from: Nothing

Floats, strings, and vars can be cast to integers. Floating point values will be truncated, and strings will convert to their integer representation, if it has one (otherwise 0). Vars will convert to whatever their contents would convert to, or 0 if their contents cannot be cast.

Cast to Float
Compiler auto-cast from: Int

Integers, strings and vars can be cast to floats. Integers will simply be their floating point equivalents, and strings will convert to their float representation, if it has one (otherwise 0.0). Vars will cast to whatever their contents would have cast to, or 0.0 if their contents won't cast to floats.

Cast to String
Compiler auto-cast from: Anything

Anything can be cast to strings. The result that you get depends on the type of object that you are casting from, according to the following table:

Cast to Object
Compiler auto-cast from: Child object

Only other objects or vars can be cast to objects, and only if that object is a direct child or parent of the one being cast. If you are casting from the parent object to the child one, the cast may fail if it isn't actually an instance of the child object, in which case the result will be None. If you attempt to cast a non-object var to an object, the result will also be None.

Cast to Array
Compiler auto-cast from: Nothing

Arrays can cast to other arrays, but only explicitly, and only if their elements could be cast. Casting arrays makes a copy of the array, and elements that fail to cast will end up as None, 0, or equivalent.

Cast to Struct
Compiler auto-cast from: Nothing

Nothing can be cast to a struct.

Cast to Var
Compiler auto-cast from: Everything but arrays

Everything except arrays can be cast to the var type. The variable will then internally hold that value and remember what type it is.