Difference between revisions of "SetBit"

From the Fallout3 GECK Wiki
Jump to navigation Jump to search
imported>Odessa
(adapted from nvse_whatsnew)
 
imported>Odessa
(0-indexed, and don't use for bit > 29. source jaam.)
Line 1: Line 1:
{{Function
{{Function
  |origin = NVSE
  |origin = NVSE
  |summary = Returns the specified int with the specified bit set to 1, or optionally 0 (cleared).
  |summary = Returns the specified int with the specified bit set to 1, or optionally 0 (cleared). This function is useful for manipulating bitmasks.
  |name = SetBit
  |name = SetBit
  |alias =  
  |alias =  
Line 7: Line 7:
  |referenceType =  
  |referenceType =  
  |arguments = {{FunctionArgument
  |arguments = {{FunctionArgument
   |Name = ValueToChange
   |Name = Target
   |Type = int
   |Type = int
   }}{{FunctionArgument
   }}{{FunctionArgument
Line 13: Line 13:
   |Type = int
   |Type = int
   }}{{FunctionArgument
   }}{{FunctionArgument
   |Name = ValueToSet
   |Name = NewBitValue
   |Type = bool
   |Type = bool
   |Optional = y
   |Optional = y
Line 27: Line 27:
; a is now 13
; a is now 13
</pre>
</pre>
==Notes==
*SetBit considers the first bit be numbered, <b>0</b>, and the final bit to be <b>31</b>; however, it should not be used to change bits greater than 29 to avoid sign and float conversion issues.
==See Also==
==See Also==
*[[ClearBit]]
*[[ClearBit]]
*[[SetEquipmentSlotsMask]]
*[[SetEquipmentSlotsMask]]
*[[SetWeaponFlags1]]
*[[SetActorBaseFlagsLow]]
[[Category:Functions_(NVSE)]]
[[Category:Functions_(NVSE)]]

Revision as of 14:50, 11 March 2015

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

A function added by the New Vegas Script Extender.

Description

Returns the specified int with the specified bit set to 1, or optionally 0 (cleared). This function is useful for manipulating bitmasks.

Syntax

[help]
(int) SetBit Target:int BitToSet:int NewBitValue:bool

Example

int a
set a to 11		; bits 0, 1, 3 set
set a to SetBit a, 2	; sets bit 2 (value 4)
; a is now 15
set a to SetBit a, 1, 0	; would set bit 1 (value 2), but the third parameter is 0 so instead it clears the bit
; a is now 13

Notes

  • SetBit considers the first bit be numbered, 0, and the final bit to be 31; however, it should not be used to change bits greater than 29 to avoid sign and float conversion issues.

See Also