View Full Version : Length of variable

05/04/2012, 07:19 PM
I done reading ******' tutorial about strings and such where he said that new string[256] is wrong and [128] is better etc..
But when I tried to change this:
new reason[256];
reason = strrest(cmdtext,idx);
To this:
new reason[128];
reason = strrest(cmdtext,idx);

It gave me the next error:
error 047: array sizes do not match, or destination array is too small

05/04/2012, 07:39 PM
Show the code, also, is idx a string? if it is, what is their size?

05/04/2012, 07:44 PM
idx has undefined size.
if(!strcmp(cmd,"/kick", true))
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,COLOR_RED,"[Error:] You're not an administrator!");
tmp = strtok(cmdtext,idx);
new id = strval(tmp);
if(!strlen(tmp)) return SendClientMessage(playerid,COLOR_WHITE,"[USAGE:] /kick [ID] [Reason]");
if(!IsPlayerConnected(id)) return SendClientMessage(playerid,COLOR_RED,"[Error:] Invalid ID");
new reason[256];
reason = strrest(cmdtext,idx);
format(string, sizeof(string),"AdmCmd: %s was kicked by %s, Reason: %s",GetName(id),GetName(playerid),reason);
SendClientMessageToAll(0xFF9900AA, string);
return 1;

05/04/2012, 07:47 PM
Where you define the variable"tmp"?

05/04/2012, 07:59 PM
Basically that's because whoever wrote the "strrest" function that you are using didn't follow that advice either. Anyway, you are MUCH better off learning y_commands (or ZCMD) and sscanf for writing commands - they make the whole thing vastly easier. Anyway, "strrest" is a completely pointless function as "cmdtext" already contains all the rest of itself so there's no need at all to copy it to another variable.

But the usage is /kick [id] [reason] so the id takes the cmdtext spot, I need a new one for the reason.
And yeah I'll learn ycmd sometime soon.