28.02.2012, 18:16
A normal variable can hold values that are between -2,147,483,648 and 2,147,483,647 (as in Slice's explanation)
This makes the variable have a size of 4 bytes in each cell.
But a char variable can ONLY hold values within the range of 0 and 255. So, it has a smaller size of 1 byte per cell.
Try this code:
So, you should use char arrays only when you are sure that the value an index is holding doesn't exceed 255 or get less than 0.
List of things you can & cannot do using char arrays:
- Admin levels 0-5 (not 1337 though) : Yes!
- Vip Ranks : Yes!
- Money : No, it exceeds the value of 255
- Score : Nope.
- As Textdraw vars : No, Textdraw Ids can go beyond 255 too.
Now you can think of the rest!
This makes the variable have a size of 4 bytes in each cell.
But a char variable can ONLY hold values within the range of 0 and 255. So, it has a smaller size of 1 byte per cell.
Try this code:
pawn Code:
public OnFilterScriptInit()
{
new cell_Variable[2];
cell_Variable[0] = 2147483647;
cell_Variable[1] = -2147483647;
printf("CELL: %i || %i ", cell_Variable[0], cell_Variable[1]);
// It shows that it hold such huge values.
new char_Variable[2 char];
char_Variable{0} = 255; // This var cannot hold any value more that 255 (like a normal one)
char_Variable{1} = 0; //And also no negative values, Remember (0-255)
printf("CHAR: %i || %i ", char_Variable{0}, char_Variable{1});
return true;
}
pawn Code:
new Variable[2048]; //It has a size of 2048 * 4 bytes = 8192 bytes.
new char_Variable[2048 char]; //It has a size of 2048 * 1 byte = 2048 bytes.
//But it has a limitation in the value it holds...
List of things you can & cannot do using char arrays:
- Admin levels 0-5 (not 1337 though) : Yes!
- Vip Ranks : Yes!
- Money : No, it exceeds the value of 255
- Score : Nope.
- As Textdraw vars : No, Textdraw Ids can go beyond 255 too.
Now you can think of the rest!

