Help with DINI & Arrays
#1

So, this is my first time working with DINI. Don't say I need to use Y_INI, because IMO DINI is easier to work with.
I have made an invite command, but it gives me an when I add my orgs to it.

My cmd:
pawn Код:
CMD:invite(playerid, params[])
{
    if(PlayerInfo[playerid][pLeader] == 1)
    {
        new pID, message1[170];
        if(sscanf(params,"u",pID)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /invite [playerid]");
        if(pID == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_GRAD2, "This user is not online!");
        {
            new jtext[50];
            new file[32];
            format(file,sizeof(file),"/Orgs/org%d.ini", PlayerInfo[playerid][pFamily]);
            if(PlayerInfo[playerid][pFaction] == 1) { jtext = "Police Force"; }
            else if(PlayerInfo[playerid][pFaction] == 2) { jtext = "Los Santos MD"; }
            else if(PlayerInfo[playerid][pFaction] == 3) { jtext = "Hitman Agency"; }
            else if(PlayerInfo[playerid][pFaction] == 4) { jtext = "Los Santos Government"; }
            else if(PlayerInfo[playerid][pFaction] == 5) { jtext = "Whore Company"; }
            else if(PlayerInfo[playerid][pFaction] == 6) { jtext = "FBI"; }
            else if(PlayerInfo[playerid][pFamily] >= 1) { jtext = dini_Get(file,"Name"); }
            format(message1, sizeof(message1), "%s has invited you to join the %s, (type /accept invite) to accept.", GetName(playerid), jtext);
            SendClientMessage(pID, COLOR_LIGHTBLUE, message1);
            format(message1,sizeof(message1), "You've invited %s to join the %s!", GetName(pID), jtext);
            SendClientMessage(playerid, COLOR_LIGHTBLUE, message1);
           
            if(PlayerInfo[playerid][pFaction] != 0)
            {
                PlayerInfo[pID][pInvite] = PlayerInfo[playerid][pFaction];
            }
            else if(PlayerInfo[playerid][pFamily] != 0)
            {
                PlayerInfo[pID][pFInvite] = PlayerInfo[playerid][pFamily];
            }
            InvitedBy[pID] = playerid;
        }
    }
    return 1;
}
The problem is here:

pawn Код:
else if(PlayerInfo[playerid][pFamily] >= 1) { jtext = dini_Get(file,"Name"); }
Here are my errors:

Код:
C:\Program Files\GTA San Andreas (2)\server\Basic Roleplay\gamemodes\hrp.pwn(2279) : error 047: array sizes do not match, or destination array is too small
C:\Program Files\GTA San Andreas (2)\server\Basic Roleplay\gamemodes\hrp.pwn(2387) : error 047: array sizes do not match, or destination array is too small
C:\Program Files\GTA San Andreas (2)\server\Basic Roleplay\gamemodes\hrp.pwn(4974) : warning 203: symbol is never used: "ret_memcpy"
C:\Program Files\GTA San Andreas (2)\server\Basic Roleplay\gamemodes\hrp.pwn(961) : warning 204: symbol is assigned a value that is never used: "tajpickup"
C:\Program Files\GTA San Andreas (2)\server\Basic Roleplay\gamemodes\hrp.pwn(962) : warning 204: symbol is assigned a value that is never used: "trjpickup"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


2 Errors.
As yo ucan see I have 2 errors because I tried to make it work on another cmd too. It's the same problem.
Anybody knows how to fix it? I've tried making the array larger, but that didn't work.
Reply
#2

You need to make a choice between what is easy, and what is right.

The size of your 'jtext' variable needs to be equal or bigger than the size of the string that dini_Get returns. I don't know what size it is, so look it up in the include.
Reply
#3

I've looked it up and it's smaller than 50 characters, so the array should work. But it doesn't...
I've even tried to set it to 200 to see if it worked, but I get the same error.

I've tried to look up the stock for dini_Get, and I found this:

pawn Код:
stock dini_Get(filename[],key[]) {
    new tmpres[DINI_MAX_STRING];
   
    new key_length = strlen(key);
    if (key_length==0 || key_length+2>DINI_MAX_STRING) return tmpres;
   
    new File:fohnd;
    fohnd=fopen(filename,io_read);
    if (!fohnd) return tmpres;
   
    while (fread(fohnd,tmpres)) {
        if (
            tmpres[key_length]=='='
            && !strcmp(tmpres, key, true, key_length)  
        ) {
            /* We've got what we need */
            DINI_StripNewLine(tmpres);
            strmid(tmpres, tmpres, key_length + 1, strlen(tmpres), DINI_MAX_STRING);
            fclose(fohnd);
            return tmpres;
        }
    }
    fclose(fohnd);
    return tmpres;
}
I don't know if this helps anyting.

EDIT: I've found DINI_MAX_STRING, which is 255.

EDIT2: I've changed the arrays to 255 and the errors are gone. One more question: because the arrays are bigger, will it slow down my server/the cmd for a bit?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)