PackBytes

int PackBytes(int byte1, int byte2, int byte3, int byte4)

Description

Packs four bytes into one integer and returns the result. The bytes must be in [0, 255] range.

The packed values can be retrieved using UnpackByte.

It is intended to be used to pass more than 3 or 4 arguments to a script if the range of the values is small.You can also pack shorts (-32768 to 32767) using PackShorts. If you need more extreme packing, you should code it yourself.

Examples

int packed = PackBytes(10, 11, 12, 13);
UnpackByte1(packed) -> 10
UnpackByte2(packed) -> 11
UnpackByte3(packed) -> 12
UnpackByte4(packed) -> 13

Passing a color to a script:

function void SomeFunction(void)
{
// red, green, blue, alpha
int color = PackBytes(255, 128, 0, 128);
ACS_ExecuteAlways(somescript, 0, x, y, color);
}
script somescript (int x, int y, int color)
{
int r = UnpackByte1(color);
int g = UnpackByte2(color);
int b = UnpackByte3(color);
int a = UnpackByte4(color);
}

See also

PackShorts