Length of variable
#1

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
Reply
#2

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

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;

Reply
#4

Where you define the variable"tmp"?
Reply
#5

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)