error 047: array sizes do not match, or destination array is too small
#1

I tried every single way around this error, it just doesn't want to work. I am trying to save a hex string in an array but whenever I do so, it gives me this error: error 047: array sizes do not match, or destination array is too small

The array in the enum is exactly same as in the command. Here is the observable code:

PHP код:
enum PLAYER_DATA
{
        
donorlevel,
    
color[6],
    
chatcolor[6],
}
new 
pinfo[MAX_PLAYERS][PLAYER_DATA];
public 
OnPlayerText(playeridtext[])
{
    switch(
pinfo[playerid][donorlevel])
        {
            case 
5:
        {
            new 
str[256];
            if(
pinfo[playerid][usingnick] == 1)
            {
                
format(str,sizeof(str),"{%x}%s (%d): {%x}%s",pinfo[playerid][color],pinfo[playerid][nickname],playerid,pinfo[playerid][chatcolor],playerid,text);
                
SendClientMessageToAll(-1,str);
            }
            else
            {
                
format(str,sizeof(str),"{%x}%s (%d): {%x}%s",pinfo[playerid][color],pinfo[playerid][name],playerid,pinfo[playerid][chatcolor],playerid,text);
                
SendClientMessageToAll(-1,str);
            }
        }
    }
    return 
0;

and the command:
PHP код:
CMD:changecolor(playerid,params[])
{
    new 
plcolor[50];
    if(
pinfo[playerid][donorlevel] < 1) return 0;
    else if(
pinfo[playerid][donorlevel] < 5) return SendClientMessage(playerid,COLOR_RED,"ERROR: Only donors level 5 have access to this command.");
    if(
sscanf(params"s",plcolor)) return SendClientMessage(playerid,COLOR_RED,"USAGE: /changecolor [color]");
    if(!
strcmp(plcolor,"red"))
    {
        
pinfo[playerid][color] = "ff0000"//line 466
        
pinfo[playerid][chatcolor] = "ff4c4c"//line 467
    
}
    if(!
strcmp(plcolor,"blue"))
    {
        
pinfo[playerid][color] = "00ffff"//line 471
        
pinfo[playerid][chatcolor] = "66ffff"//line 472
    
}
    if(!
strcmp(plcolor,"yellow"))
    {
        
pinfo[playerid][color] = "FFFF00"//line 476
        
pinfo[playerid][chatcolor] = "ffff66"//line 477
    
}
    if(!
strcmp(plcolor,"black"))
    {
        
pinfo[playerid][color] = "1e1e1e"//line 481
        
pinfo[playerid][chatcolor] = "616161"//line 482
    
}
    return 
1;

and the errors I am getting:
Код:
C:\Users\Abderrahmene\Desktop\0.3.7\gamemodes\testserver1.pwn(466) : error 047: array sizes do not match, or destination array is too small
C:\Users\Abderrahmene\Desktop\0.3.7\gamemodes\testserver1.pwn(467) : error 047: array sizes do not match, or destination array is too small
C:\Users\Abderrahmene\Desktop\0.3.7\gamemodes\testserver1.pwn(471) : error 047: array sizes do not match, or destination array is too small
C:\Users\Abderrahmene\Desktop\0.3.7\gamemodes\testserver1.pwn(472) : error 047: array sizes do not match, or destination array is too small
C:\Users\Abderrahmene\Desktop\0.3.7\gamemodes\testserver1.pwn(476) : error 047: array sizes do not match, or destination array is too small
C:\Users\Abderrahmene\Desktop\0.3.7\gamemodes\testserver1.pwn(477) : error 047: array sizes do not match, or destination array is too small
C:\Users\Abderrahmene\Desktop\0.3.7\gamemodes\testserver1.pwn(481) : error 047: array sizes do not match, or destination array is too small
C:\Users\Abderrahmene\Desktop\0.3.7\gamemodes\testserver1.pwn(482) : error 047: array sizes do not match, or destination array is too small
Reply
#2

I'm just going to say, there'll be a better way of doing this.

Such as defining the chat colors, and simply using the chat callback to check for their status and format the text itself without storing the individual colors in the enums for the player.


Use the enums color selection as a setting, check that, and format the message accordingly based on that result.



While what I say 'avoids the issue', I really do think that later on, this approach that you've taken, would lead to problems.

The only reason I would continue going down this path you've taken, is if you were going to have custom color options for the chat.

Being these are static colors, there's no real reason to be running them in the enum itself.
Reply
#3

That's not the idea I am trying to make. I am making a donor system whereas this level (5), you can select a custom color and and that color you selected has its own chat color.

Correct me if I didn't answer your question accordingly.

EDIT: This is what I am trying to do:
you use "/changecolor red" for example. when you type in the chat, the color would be something like this:
"Mag (0): Test".

So I am trying to store the color manually when you execute the command, when I try to define the colors with #define, this is what I get:

PHP код:
#define RED ff0000
CMD:changecolor(playerid,params[])
{
    new 
plcolor[50];
    if(
pinfo[playerid][donorlevel] < 1) return 0;
    else if(
pinfo[playerid][donorlevel] < 5) return SendClientMessage(playerid,COLOR_RED,"ERROR: Only donors level 5 have access to this command.");
    if(
sscanf(params"s",plcolor)) return SendClientMessage(playerid,COLOR_RED,"USAGE: /changecolor [color]");
    if(!
strcmp(plcolor,"red"))
    {
        
pinfo[playerid][color] = RED//line 467 
Error:

Код:
C:\Users\Abderrahmene\Desktop\0.3.7\gamemodes\testserver1.pwn(467) : error 017: undefined symbol "ff0000"
Reply
#4

It wasn't a question, it was all a statement.

You need to shift from storing the color in the enum, and use it simply as a value, to use as a setting, and when you are trying to do that one format, use that setting to bring out the right format using a case check.


As I said, the idea of doing it this way, unless you are making allowance for custom enter-able colors, is only going to give you more headaches.
Reply
#5

I honestly cannot seem to understand your statement, what do you mean by value and setting?

What do I exactly put in the /changecolor command and how do I retrieve the color chosen to be used in OnPlayerText?
Reply
#6

Rather than storing the color as an rgb value, and trying to insert it into the text as hex, simply make the color value, a setting, an integer, so it goes 1 2 3 4 - 2174664 and you simply use those settings to check which color to format within a case statement.


If you then expand the system more, you could make a function to make that preformat the line so it doesn't need to be done a whole heap of times in the script itself.

In the current scenario of 4 colors, you'd only have it check on the OnPlayerText callback, but if you added more features, such as a car material text that used the same formatting, or a 3dtext, or something other than the onplayertext then you'd look at a function.



Probably to cut the error, all you'd need to do is make color[7], but as I've been mentioning, it's not such a good idea unless you are doing custom colors via RGB selection/text entry.


I also edit a lot, so re-read and refresh what I've put up.




ANNNNNDDD, a real good mess about to check out new methods, is to use a fresh new.pwn, and put the basics of what you need, in there, and see what you can produce.
Reply
#7

Код:
C:\Users\Abderrahmene\Desktop\0.3.7\gamemodes\testserver1.pwn(467) : error 017: undefined symbol "ff0000"
put this
#define ff0000
Reply
#8

Fix it properly and make your script more capable for the future.


And it's encouraging to see you try this...

PHP код:
pinfo[playerid][color] = RED
and if you used this, set your defines to

PHP код:
#define RED 1
#define YELLOW 2
#define GREEN 3 
And use case on pinfo[playerid][color] checking for the color, and formatting in that result where it's checked on the area you're formatting the text and displaying it.


This last portion, is what you'd look at putting in a function if you used it in more scenarios.



And, color in this instance wouldn't need to be the array... It'll simply be color.
Reply
#9

I actually fixed it where I just made it the opposite, this is how I fixed it:

command:
PHP код:
CMD:changecolor(playerid,params[])
{
    new 
plcolor[256],path[256];
    if(
pinfo[playerid][donorlevel] < 1) return 0;
    else if(
pinfo[playerid][donorlevel] < 5) return SendClientMessage(playerid,COLOR_RED,"ERROR: Only donors level 5 have access to this command.");
    if(
sscanf(params"s",plcolor)) return SendClientMessage(playerid,COLOR_RED,"USAGE: /changecolor [color]");
    
format(path,sizeof(path),"users/%s.ini",pinfo[playerid][name]);
    
pinfo[playerid][color] = plcolor;
    
dini_Set(path,"Donor color",plcolor);
    return 
1;

OnPlayerText:
PHP код:
public OnPlayerText(playeridtext[])
{
    switch(
pinfo[playerid][donorlevel])
    {
        case 
5:
        {
            if(
strcmp(pinfo[playerid][color],"green") && strcmp(pinfo[playerid][color],"pink") && strcmp(pinfo[playerid][color],"orange") && strcmp(pinfo[playerid][color],"purple") && strcmp(pinfo[playerid][color],"yellow") && strcmp(pinfo[playerid][color],"blue") && strcmp(pinfo[playerid][color],"black") && strcmp(pinfo[playerid][color],"red"))
            {
                
SendClientMessage(playerid,COLOR_RED,"ERROR: something wrong occured while trying to send this message. Please check the color you chose. use /changecolor");
                return 
0;
            }
            else if(!
strcmp(pinfo[playerid][color],"red"))
            {
                new 
str[256];
                  if(
pinfo[playerid][usingnick] == 1)
                {
                      
format(str,sizeof(str),"{ff0000}%s (%d): {ff4c4c}%s",pinfo[playerid][nickname],playerid,text);
                    
SendClientMessageToAll(-1,str);
                }
                else
                {
                     
format(str,sizeof(str),"{ff0000}%s (%d): {ff4c4c}%s",pinfo[playerid][name],playerid,text);
                    
SendClientMessageToAll(-1,str);
                }
            } 
Even though this is a little bit lazy work, I can still put the colors in a dialog and there wouldn't be any error occuring for false color.

However, thank you for your help, Sew_Sumi. I kind of reformed what you suggested
Quote:

And use case on pinfo[playerid][color] checking for the color, and formatting in that result where it's checked on the area you're formatting the text and displaying it.

Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)