Eval
From GECK
A function added by the New Vegas Script Extender.
Description
Reduces an expression to a boolean for use in if conditional statements. Used to permit the usage of any function or expression that may be so reduced for this purpose. Eval significantly expands the scripting functionality of if-statements as it supports NVSE Expressions. With xNVSE 6, Eval supports short-circuiting the logical operators && and ||.
Eval is required to test the value of user defined functions, and those related to arrays and strings in if conditionals, as the vanilla compiler will otherwise misunderstand them. This is because these were added by NVSE, and hence were not present when the original scripting language was created.
Syntax
(boolean) eval AnyReducable:expression
Example
if eval SomeStringVar == "this string" ; SomeStringVar has contents "this string" endif if eval SomeArray[3] == SomeValue ; Element at index 3 of SomeArray equals SomeValue endif if eval (call SomeSuitableUDF) ; The user defined function returns true endif if eval SomeInt == 5 ; * including 'eval' here is not necessary, but is harmless elseif eval !(SomeActor.GetDead) ; * elseif can be used as usual ; SomeActor is _not_ dead, (note '!') else ; else can be used as usual endif
Notes
- If struggling to understand the purpose of 'eval', then by analogy think of 'if eval' as simply telling the GECK compiler the line is written in NVSE language, to prevent it complaining with an error.
- Eval is not required for NVSE aware conditions, such as While.
- Whilst not necessary, it is harmless to include 'eval' in any 'if' statement (when testing vanilla functions, for example). There is a possible advantage to this, in that when an illegitimate eval statement fails (example, testing certain functions on an empty ref var), an error message will be printed to the game console, rather than silently failing.