Table of Contents

PackShorts

int PackShorts(int short1, int short2)

Description

Packs two short integers (-32768 to 32767) into one integer and returns the result.

The packed values can be retrieved using UnpackShortX.

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 individual bytes (0 to 256) using PackBytes.

If you need more extreme packing, you should code it yourself.

Examples

int packed = PackShorts(12345, -15000);
UnpackShort1(packed) -> 12345
UnpackShort2(packed) -> -15000

Passing a 2D actor position to a script:

function void SomeFunction(void)
{
    // Pack rounded 2D actor position into a single integer.
    int pos = PackShorts(GetActorX(0)>>16, GetActorY(0)>>16);
    ACS_ExecuteAlways(somescript, 0, stuff1, stuff2, pos);
}

script somescript (int stuff1, int stuff2, int pos)
{
    // Extract actor position
    int x = UnpackShort1(pos);
    int y = UnpackShort2(pos);
}