GetObjectType

From GECK
(Redirected from GetType)
Jump to: navigation, search


A function added by the Fallout Script Extender.

Description

Returns the type code of the specified Base Form, or calling Reference. If a reference is passed, its BaseForm is derived.

Syntax

[help]
(TypeCode:int) reference.GetObjectType BaseForm 

Or:

(TypeCode:int) reference.GetType BaseForm 

Example

Calling on a known reference:

int iType

let iType := SunnyRef.GetType
print $iType 
;* Should print "42", which is the NPC form type.

Calling on a known Base Form:

int iType

let iType := GetType GSSunnySmiles
print $iType 
;* Should print "42", which is the NPC form type.

Working With Ref Variables:

  • Reminder: While Ref Variables sound awfully like "Reference Variable", they can hold either Base Forms or References.


If the ref variable is guaranteed to be a Base Form:

ref rRef
int iType

let iType := GetType rRef

If the ref variable is guaranteed to be a Reference:

ref rRef
int iType

let iType := rRef.GetType

If you're not sure if the ref variable will be valid, it is always important to verify using IsFormValid / IsReference. Not doing so can cause problems; this applies to other functions as well.

In the interest of debugging such issues, it is recommended to use "Let :=" over "Set to", as Let just as fast (if not faster in some cases) and will report errors if attempting to call functions with the wrong syntax / with invalid forms.

The following will cover a few examples of how to use these functions in conjunction with GetType, in order to avoid errors and crashes.

To verify if the ref variable holds either a Base Form or a Reference:

ref rRef

if IsFormValid rRef
   ; Unless we can assume rRef will be a Reference or a Base Form,
   ;... it is unsafe to proceed without further filtering.
endif

To verify if the ref variable holds a Base Form:

ref rRef
int iType

if IsFormValid rRef
   if IsReference rRef != 1
      ; rRef is a Base Form.
      let iType := GetType rRef
      if iType == 41 ; ammo
         ; do something appropriate for ammo
      endif
   endif
endif

To verify if the ref variable holds a Reference:

ref rRef

if IsReference rRef
  if (rRef.GetType) == 24 ; Armor
     ; do something appropriate for Armor
  endif
endif

To verify if the ref variable holds either a Base Form or a Reference, and to be able to act in either case:

ref rRef
int iType

if IsFormValid rRef
   if IsReference rRef != 1
      ; rRef is a Base Form.
      let iType := GetType rRef
      if iType == 41 ; ammo
         ; do something appropriate for ammo
      endif
   else
      ; rRef is a Reference.
      let iType := rRef.GetType 
      if iType == 41 ; ammo
         ; do something appropriate for ammo
      endif
   endif
endif

See Also