Sv Count

From the Fallout3 GECK Wiki
Jump to navigation Jump to search
< [[::Category:Functions|Category:Functions]]

A function added by the New Vegas Script Extender.

Description

Added by NVSE V4. Returns the number of occurrences of some sub string within a string variable. By default it is case insensitive, but an optional flag is available to change this.

The first argument is a string, which may have optional formatting information thereafter. This is what you want to count.

The second argument (ignoring the optional formatting) is a string variable within which to search for the first string.

There are three optional int arguments at the very end: a start position and end position, which allow searching of a substring of the string_var, and finally, a boolean flag to enable case sensitivity.

Syntax

[help]
(int) Sv_Count ToFind:string 20xOptional:formatting Within:string_var StartPos:int EndPos:int CaseSensitiveFlag:int

Simplified

(int) Sv_Count ToFind:string Within:string_var

Example

string_var my_message

let my_message := "The owls are not what they seem"

Sv_Count "owls", my_message ; will return 1
Sv_Count "foxes", my_message ; will return 0
Sv_Count "the", my_message ; will return 2: found in words 'The' and 'they'

Another example, maybe you want to be able to specify complex script instructions as a single string?

string_var my_instructions
ref rActor

if eval (Sv_Count "sunny smiles", my_instructions)
    let rActor := SunnyREF
else
    let rActor := PlayerREF
endif

if eval (Sv_Count "kill", my_instructions) > 2
    ; kill actor if I get asked 3 times
    rActor.Kill
elseif eval (Sv_Count "move", my_instruction)
    ; move actor if I get asked one or more times. 
    rActor.MoveTo PlayerREF 
endif

See Also