This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
functions:packbytes [2017/03/19 17:36] – korshun | functions:packbytes [2017/03/19 18:10] – korshun | ||
---|---|---|---|
Line 4: | Line 4: | ||
===== Description ===== | ===== Description ===== | ||
- | Packs four bytes into one integer and returns the result. The bytes' values | + | Packs four bytes into one integer and returns the result. The bytes must be in the [0, 255] range. |
The packed values can be retrieved using [[UnpackByte]]. | The packed values can be retrieved using [[UnpackByte]]. | ||
- | This functions can be used to pass more than 3 or 4 arguments to a script | + | <note tip> |
+ | It is intended to be used to pass more than 3 or 4 arguments to a script | ||
+ | |||
+ | You can also pack shorts (-32768 to 32767) using [[PackShorts]]. | ||
+ | |||
+ | If you need more extreme packing, you should code it yourself.</ | ||
===== Examples ===== | ===== Examples ===== | ||
Line 21: | Line 26: | ||
Passing a color to a script: | Passing a color to a script: | ||
< | < | ||
- | int color = PackBytes(255, | + | function void SomeFunction(void) |
- | ACS_ExecuteAlways(somescript, | + | { |
+ | // red, green, blue, alpha | ||
+ | | ||
+ | ACS_ExecuteAlways(somescript, | ||
+ | } | ||
+ | |||
+ | script somescript (int x, int y, int color) | ||
+ | { | ||
+ | int r = UnpackByte1(color); | ||
+ | int g = UnpackByte2(color); | ||
+ | int b = UnpackByte3(color); | ||
+ | int a = UnpackByte4(color); | ||
+ | } | ||
</ | </ | ||
+ |