Difference between revisions of "Eval"

From the Fallout3 GECK Wiki
Jump to navigation Jump to search
imported>Odessa
(Created)
 
imported>Odessa
(clarified purpose)
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Function
{{Function
  |origin = NVSE
  |origin = NVSE
  |summary = Added by NVSE V4. Reduces an expression to a boolean for use in conditional statements. Used to permit the usage of any function or expression that may be so reduced.  
  |summary = Added by NVSE V4. Reduces an expression to a boolean for use in <b>if</b> conditional statements. Used to permit the usage of any function or expression that may be so reduced for this purpose.


Eval is required to test the value of [[User Defined Function|user defined functions]], and those related to [[Array Variables|arrays]] and [[String Variables|strings]] in conditionals.
Eval is required to test the value of [[User Defined Function|user defined functions]], and those related to [[Array Variable|arrays]] and [[String Variable|strings]] in <b>if</b> 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.  


  |name = Eval
  |name = eval
  |returnType = boolean
  |returnType = boolean
  |arguments =  
  |arguments =  
   {{FunctionArgument
   {{FunctionArgument
   |Name = expression
   |Name = AnyReducable
   |Type = reducable
   |Type = expression
   }}
   }}
   }}
   }}
==Example==
==Example==
<pre>
<pre>
array_var aBeatles


let aBeatles := ar_List JohnREF, PaulREF, GeorgeREF, RingoREF
if eval SomeStringVar == "this string"
  ; SomeStringVar has contents "this string"
endif
 


if eval (aBeatles[3] == RingoREF)
if eval SomeArray[3] == SomeValue
     ; Do something
     ; Element at index 3 of SomeArray equals SomeValue
endif
endif




if eval (Ar_Size aBeatles > 0)
if eval (call SomeSuitableUDF)  
     ; Do something
     ; The user defined function returns true
endif
endif




if eval (Call SomeSuitableUDF)
if eval SomeInt == 5
    ; Do something
  ; * 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
endif
</pre>
</pre>
==Notes==
==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.
*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.
*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 [[NVSE Error|error message]] will be printed to the game console, rather than silently failing.
*Eval is not required for NVSE aware conditions, such as [[While]].
==See Also==
==See Also==
*[[User Defined Functions]]
*[[TestExpr]]
*[[Array Variables]]
*[[User Defined Function]]
*[[String Variables]]
*[[Array Variable]]
[[Category:Functions_(NVSE)]]
*[[String Variable]]
*[[Script Compiler Override]]
==External Links==
*[http://obse.silverlock.org/obse_command_doc.html#OBSE_Expressions List of supported expression found in OBSE, these are equivalent in NVSE]
*[http://fallout.bethsoft.com/eng/links/privacyredirect.php?site=http://www.loverslab.com/topic/26749-tutorial-nvse4-part-1-syntax-and-expressions/ Tutorial on syntax and expressions in NVSE 4]
 
[[Category:Commands]]
[[Category:Commands]]
[[Category:Scripting]]
[[Category:Scripting]]
[[Category:Functions_(NVSE)]]
[[Category:Array Variables]]
[[Category:String Variables]]
[[Category:User Defined Functions]]

Latest revision as of 07:29, 28 August 2014

< [[::Category:Functions|Category:Functions]]

A function added by the New Vegas Script Extender.

Description

Added by NVSE V4. 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 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

[help]
(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.
  • 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.
  • Eval is not required for NVSE aware conditions, such as While.

See Also

External Links