PDA

View Full Version : ARRAY PROBLEMS


pelican1
23/04/2017, 03:08 PM
const MYARRAY[10][3][20] =
{
{"allum", 0x33CCFFAA, 25},
{"alldm", 0x33CCFFAA, 25},
{"allem", 0x33CCFFAA, 25},
{"allsm", 0x33CCFFAA, 25},
{"allxm", 0x33CCFFAA, 25},
{"allqm", 0x33CCFFAA, 25},
{"allam", 0x33CCFFAA, 164},
{"allom", 0x33FF33AA, 292},
{"allgm", 0xFF0000AA, 299},
{"allsm", 0xFFFF00AA, 82}
};



Hi!
My arrays does not work when i put , the middle column in sendclientmessage color; It creates an error. what can i do

thanks

NaS
23/04/2017, 03:25 PM
All of the indexes are now arrays, meaning the color and the number at the end will not be retrieved as integer, but as array.

You have two options to do this, either with an enum (which would be the best solution here) or you access the Array differently.

To do it with an enum you should make it like this:


enum TestEnum
{
teString[20], // I always name enum entries with any prefix to avoid global conflicts
teColor,
teNumber
};

new MYARRAY[10][TestEnum] = // This array will now have 10 x 3 indexes, one of which is an array and two are cells
{
{"test", 0x55667788, 22},
{"test2", 0x99112233, 33},
// etc...
};

// And to access any of those indexes:

SendClientMessage(playerid, MYARRAY[0][teColor], MYARRAY[0][teString]);


The other way would be obtaining the color by doing

SendClientMessage(playerid, MYARRAY[0][1][0], MYARRAY[0][0]);

But that is not so nice, in two ways - it's ugly (not that clear) and also a waste of memory - you assign 2x 20 bytes for each slot of MYARRAY just to hold one value. The enum looks nicer and saves you that, I strongly suggest doing it that way.

pelican1
23/04/2017, 03:29 PM
Thanks! very well explained!