Two Dimensional String Problem
#1

So, thats my code..

Quote:

new string[2][128];
format(string[0],sizeof(string[0]), "{10F441}[VIP] {10F441}%s's {FFFFFF}VIP level has been set to {10F441}%d.", pInfo[pID][pName], vlevel);
SendClientMessage(playerid, -1, string[0]);
format(string[1],sizeof(string[1]), "{10F441}[VIP] {FFFFFF}Your VIP level has been set to {10F441}%d. {FFFFFF}Use {10F441}/vcmds {FFFFFF}to see available commands.", vlevel);
SendClientMessage(pID, -1, string[1]);

I get these errors:
https://i.gyazo.com/f48e142b213b4b3d...c5d6e9035f.png

In this line

format(string[0],sizeof(string[0]), "{10F441}[VIP] {10F441}%s's {FFFFFF}VIP level has been set to {10F441}%d.", pInfo[pID][pName], vlevel);
Reply
#2

The red coloured characters represent the danger area, that's what's causing the problem.
Код:
new string[2][128];
format(string[0],sizeof(string[0]), "{10F441}[VIP] {10F441}%s's {FFFFFF}VIP level has been set to {10F441}%d.", pInfo[pID][pName], vlevel);
SendClientMessage(playerid, -1, string[0]);
format(string[1],sizeof(string[1]), "{10F441}[VIP] {FFFFFF}Your VIP level has been set to {10F441}%d. {FFFFFF}Use {10F441}/vcmds {FFFFFF}to see available commands.", vlevel);
SendClientMessage(pID, -1, string[1]);
to fix that, consider removing the number values from the array's bracket, just like the following.
PHP код:
new string[2][128];
format(string[0],sizeof(string[]), "{10F441}[VIP] {10F441}%s's {FFFFFF}VIP level has been set to {10F441}%d."pInfo[pID][pName], vlevel);
SendClientMessage(playerid, -1string[0]);
format(string[1],sizeof(string[]), "{10F441}[VIP] {FFFFFF}Your VIP level has been set to {10F441}%d. {FFFFFF}Use {10F441}/vcmds {FFFFFF}to see available commands."vlevel);
SendClientMessage(pID, -1string[1]); 
In order to get the size of an array, you just have to pass in the array as a parameter on sizeof() which is actually not a function, it's a compiler directive, that's why we can only get array sizes at compile time, (imagine having this on runtime, how awesome would that be?).
Let's look at these few examples:
PHP код:
new array[3][5][8];
printf("%d"sizeof(array));
printf("%d"sizeof(array[]));
printf("%d"sizeof(array[][])); 
Witch outputs:
Код:
3
5
8
Reply
#3

Thanks Eoussama learned new thing again
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)