SA-MP Forums Archive
Length of variable - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Length of variable (/showthread.php?tid=331723)



Length of variable - Tomer!.$ - 05.04.2012

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:
PHP код:
    new reason[256];
    
reason strrest(cmdtext,idx); 
To this:
PHP код:
    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


Re: Length of variable - Marricio - 05.04.2012

Show the code, also, is idx a string? if it is, what is their size?


Re: Length of variable - Tomer!.$ - 05.04.2012

idx has undefined size.
PHP код:
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(stringsizeof(string),"AdmCmd: %s was kicked by %s, Reason: %s",GetName(id),GetName(playerid),reason);
    
SendClientMessageToAll(0xFF9900AAstring);
    
Kick(id);
    return 
1;




Re: Length of variable - Marricio - 05.04.2012

Where you define the variable"tmp"?


Re: Length of variable - Tomer!.$ - 05.04.2012

Quote:
Originally Posted by ******
Посмотреть сообщение
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.