ACSUtils Wiki

An ACS library for ZDoom-based ports

User Tools

Site Tools


functions:packbytes

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
functions:packbytes [2017/03/19 17:36] – created korshunfunctions:packbytes [2017/04/17 20:47] (current) korshun
Line 1: Line 1:
 ====== PackBytes ====== ====== PackBytes ======
 {{tag>packing}} {{tag>packing}}
-''int PackBytes(int a, int b, int c, int d)''+''int PackBytes(int byte1, int byte2, int byte3, int byte4)''
  
 ===== Description ===== ===== Description =====
-Packs four bytes into one integer and returns the result. The bytes' values must be in [0, 255] range.+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 [[UnpackByteX]].
  
-This functions can be used to pass more than 3 or 4 arguments to a script in a readable way.+<note tip> 
 +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.</note>
  
 ===== Examples ===== ===== Examples =====
Line 21: Line 26:
 Passing a color to a script: Passing a color to a script:
 <code> <code>
-int color = PackBytes(255, 128, 0, 128); // red, green, blue, alpha +function void SomeFunction(void) 
-ACS_ExecuteAlways(somescript, 0, x, y, color);+
 +    // 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); 
 +}
 </code> </code>
 +
functions/packbytes.txt · Last modified: 2017/04/17 20:47 by korshun