NVSE Error



Because it performs type-checking and type-inference, NVSE can detect and report most syntax errors when compiling a script in the GECK. However, in some cases errors may be impossible to detect until the script is executed. In ambiguous cases, NVSE gives the scripter the benefit of the doubt by assuming the expression is valid. Run-time errors are logged to the console and nvse.log, along with the formID of the script which caused the error. Errors may be tested for (and the output of error messages suppressed) using the TestExpr command.


Error in script 4e0270d2

Attempting to call a function on a NULL reference or base object
    File: SomeModName.esp Offset: 0x0630 Command: Let

Common causes of run-time errors

Expressions involving array elements

Because an array element can hold a value of several types, its type is ambiguous at compile-time. For instance, an expression multiplying two array elements will compile, but will cause an error at run-time if the elements contain non-numeric values. It is the scripter's responsibility to either know that the elements are of the correct type or check their types at run-time, for which you can use TypeOf.

Uninitialized arrays

It is an error to use bracket notation to attempt to retrieve an element from an uninitialized array. Arrays are initialized by assignment, for instance by calling Ar_Construct or by assigning the return value of a command like Ar_List or GetRefs to an array variable. An uninitialized array stores an arrayID of 0, so testing if an array is initialized is as simple as: if (SomeArray).

Non-existent or out-of-bounds array index

Attempting to retrieve a value from an array using a key which does not exist in that array is an error. This can be tested using Ar_HasKey. Assigning to an element with a key which doesn't exist is fine - doing so creates an element with that key - unless the array is of the regular ('array' or 'list') type, in which case using a key which is greater than the number of elements in the array will cause an error. This can be tested using TypeOf.

Function calls

NVSE knows the return type of commands which return strings or array. However, all vanilla commands and the majority of NVSE commands do not return strings or arrays; they return either numbers or objects. At compile-time NVSE can't know which will be returned, so attempting to use the result of a command like GetInventoryObject in an arithmetic expression will result in an error at run-time. This is a scripter's error that should never be made.

Functions will also fail if called on or passed an empty Ref Variable or one that contains the wrong type, such as a base form if a reference is required. This may be avoided using functions such as IsFormValid, IsReference, GetType.

Division by zero

Attempting to divide by zero will generate an NVSE error, which can be avoided by simply checking the value.

See Also

  • TestExpr - Can be used to simply handle and suppress any errors that occur, rather than avoiding them.
Personal tools