Let

From GECK
Jump to: navigation, search


A function added by the New Vegas Script Extender.

Description

let is used for variable assignments and is best thought of as a more powerful version of the vanilla set .. to .. command.

Compared to set, it has the following advantages:

  • It supports a wider range of operators, such as += and -= for convenietly incrementing or decrementing numeric variables.
  • It supports array variables, string variables and user defined functions.
  • When an assignment fails, a runtime error message is printed to the console, naming the guilty mod and script, and the script will continue to run. By comparison, set will cause the script to fail silently, and so is harder to debug.

Let can also be called implicitly by using a Macro:

 iCount = 10        ;is equivalent to
 let iCount := 10   ;in original syntax

Syntax

[help]
(assignment) let Variable:Any Operator:Any Value:Any 

Example

Simple assignments:

ref MyRef
int MyInt

let MyInt := 5        ; equivalent to 'set MyInt to 5'
let MyRef := SunnyREF ; equivalent to 'set MyRef to SunnyREF'

Incrementing, etc

let MyInt := 5  ; 'set MyInt to 5'
let MyInt += 1  ; 'set MyInt to MyInt + 1'
let MyInt *= 10 ; 'set MyInt to MyInt * 10'
let MyInt /= 5  ; 'set MyInt to MyInt / 5'

let MyVeryLongNamedQuest.SomeVariable += 1 'set MyVeryLongNamedQuest.SomeVariable to MyVeryLongNamedQuest.SomeVariable + 1'

Strings, arrays and UDFs:

string_var my_string
array_var Beatles
int FoodCount

let my_string := "string variables are great"
let my_string += " and you can concatanate them with += too!"

let Beatles := Ar_List JohnREF, PaulREF, GeorgeREF, RingoREF

let Beatles[3] := KeithMoonREF ; swap element 3 (RingoREF for KeithMoonREF, probably a bad move ;))

let MyRef := Beatles[0] ; first element is 0, so MyRef == JohnREF

let FoodCount := call MyFoodCountingUDF PlayerREF ; call a UDF

Multiple := operators can be chained together to assign multiple variables to a single variable:

int iTemp
int iVar

let iTemp := iVar := 2

print $iTemp
print $iVar 
; * Will print "2" twice in console.

This chaining works for arrays, and any other variable type:

array_var aFolders 
array_var aFiles

;(assume both arrays were previously filled)

let aFolders := aFiles := ar_null  

ar_dump aFiles
ar_dump aFolders
; * Nothing will print to console, since both arrays are now empty.

See Also

External Links