Tutorial: String Variables 6

From GECK
Jump to: navigation, search

This is the sixth article in a tutorial series on string variables.

Passing String Variables as parameters: ToString ($)

If a vanilla or NVSE function takes one or more formatted strings as parameters:

DebugPrint "I'm a string"
MessageEx "I'm a string"
SetModelPathEx "Clutter\Junk\WhetStone.NIF"
NX_SetEVFl "some nx key string" someFloat
NX_SetEVSt "some nx key string" "some string value"

you can force them to take a string variable as parameter instead with the ToString function, in short: $

DebugPrint $sv_stringvar
MessageEx $sv_stringvar
SetModelPathEx $sv_stringvar
NX_SetEVFl $sv_keystringvar someFloat
NX_SetEVSt $sv_keystringvar $sv_valuestringvar

There are a few functions, especially fallout-specific ones and ones that are injected with NVSE plugins like MCM, that may not seem to work with ToString + string var that way - this is because they probably haven't been prepped for that. If you think this is the case in your script, try using the Script Compiler Override, which should force it.


The ToString function can also return a string representation of numbers and forms, ie pass them to a string:

It will return the name of a form if the form has a name:

let rRef := DocMitchellRef
let sv_name := $rRef
printc "%z" sv_name
  --> displays 'Doc Mitchell'

Or its hex FormID if it doesn't:

let rRef := BlackBoardMarker
let sv_name := $rRef
printc "%z" sv_name
  --> displays '00002FCC'

Numbers:

let iInt := 32
let sv_name := $iInt
printc "%z" sv_name
  --> displays '32'

Tutorial part 7: Concatenating string vars, or adding them up

External Links