problem with string [Help Please]
#1

Hello, I'm having a problem with string...
I have to define string, but when i make new string[256]; it gives me whole lot of errors...
any idea why ?
please help me...

Here's the code

pawn Code:
format(string, sizeof(string), "  You have been promoted to a level %d admin by %s", level, sendername);
There's a lot of lines that are using that string thing...so it's useless to show you them all...
I just want to know why when I define string (new string[256] it gives me 26 errors, most of them something "must be indexed"

Please help, cheers
Reply
#2

Nothing wrong with that line, can you show me more code please?
Reply
#3

show us the OnPlayerCommandText Begin ... the declared variabiles
Reply
#4

I almost guarantee that your error is coming from string being defined already. Try not defining it and just use it in print without the "new string[256];" . And on a sidenote, 256 is a little over the top for a string with the use you are intending.
Reply
#5

pawn Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
    new cmd[256];
    new tmp[256];
    new giveplayer[MAX_PLAYER_NAME];
    new sendername[MAX_PLAYER_NAME];
    new idx;



    if (strcmp(cmd, "/login", true) ==0 )
    {
      if(IsPlayerConnected(playerid))
      {
        new tmppass[64];
            if(gPlayerLogged[playerid] == 1)
            {
                SendClientMessage(playerid, COLOR_WHITE, "You are already logged in.");
                return 1;
            }
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_LIGHTBLUE, "USAGE: /login [password]");
                return 1;
            }
            strmid(tmppass, tmp, 0, strlen(cmdtext), 255);
            Encrypt(tmppass);
            OnPlayerLogin(playerid,tmppass);
        }
        return 1;
    }
    if (strcmp(cmd, "/register", true) ==0 )
    {
      if(IsPlayerConnected(playerid))
      {
        if(gPlayerLogged[playerid] == 1)
            {
                SendClientMessage(playerid, COLOR_WHITE, "You are already logged in.");
                return 1;
            }
            GetPlayerName(playerid, sendername, sizeof(sendername));
            format(string, sizeof(string), "%s.ini", sendername);
            new File: hFile = fopen(string, io_read);
            if (hFile)
            {
                SendClientMessage(playerid, COLOR_RED, "That name is alredy registered. Please change your name.");
                fclose(hFile);
                return 1;
            }
        new tmppass[64];
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_LIGHTBLUE, "USAGE: /register [password]");
                return 1;
            }
            strmid(tmppass, tmp, 0, strlen(cmdtext), 255);
            Encrypt(tmppass);
            OnPlayerRegister(playerid,tmppass);
        }
        return 1;
    }

//------------[ Make Admin cmnd ]--------------

    if(strcmp(cmd, "/makeadmin", true) == 0)
    {
      if(IsPlayerConnected(playerid))
      {
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /makeadmin [playerid/PartOfName] [level(1-3)]");
                return 1;
            }
            new para1;
            new level;
            para1 = ReturnUser(tmp);
            tmp = strtok(cmdtext, idx);
            level = strval(tmp);
            if (PlayerInfo[playerid][pAdmin] >= 1338)
            {
              if(IsPlayerConnected(para1))
              {
                if(para1 != INVALID_PLAYER_ID)
                {
                        GetPlayerName(para1, giveplayer, sizeof(giveplayer));
                        GetPlayerName(playerid, sendername, sizeof(sendername));
                        PlayerInfo[para1][pAdmin] = level;
                        printf("AdmCmd: %s has promoted %s to a level %d admin.", sendername, giveplayer, level);
                        format(string, sizeof(string), "  You have been promoted to a level %d admin by %s", level, sendername);
                        SendClientMessage(para1, COLOR_LIGHTBLUE, string);
                        format(string, sizeof(string), "  You have promoted %s to a level %d admin.", giveplayer,level);
                        SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
                        SetPlayerColor(giveplayerid,TEAM_HIT_COLOR);
                    }
                }
            }
            else
            {
                SendClientMessage(playerid, COLOR_GRAD1, "  you are not authorized to use that command!");
            }
        }
        return 1;
    }
    return 0;
}
I also searched for "new string" and I found string already defined as
pawn Code:
new string[64];
any idea how to fix it ? any help will be much appreciated, thanks

EDIT: the defined strings i found look pretty strange, like there's one onplayerlogin callback and it's new string2[64]; then it's new string3 onplayerregister etc...
what should I do ?
Reply
#6

anyone ? please, I get 26errors most of them array must be indexed and undefined something when I define string (new string[256]

how can I fix it ? cuz when I don't define I get 4 errors " undefined symbol string "
Reply
#7

Oh, maybe it is caused by bad strtok(but i dont know)
Post the lines where the errors are..
Reply
#8

Quote:
Originally Posted by Kurence
Oh, maybe it is caused by bad strtok(but i dont know)
Post the lines where the errors are..
errors :
Code:
(184) : error 017: undefined symbol "string"
(184) : error 017: undefined symbol "string"
(184) : fatal error 107: too many error messages on one line
(184) : error 029: invalid expression, assumed zero
Here's the line 184

pawn Code:
format(string, sizeof(string), "%s.ini", sendername);
Dunno what's wrong, when i define string like
pawn Code:
new string[256];
it gives me whole bunch of errors. But when I don't define it only gives me those 4 above...
anyone please ?
Reply
#9

Ok I put
pawn Code:
new string[256];
above that error line but now the problem moved to this line, and it shows the same errors just on the different line, here it is :

pawn Code:
format(string, sizeof(string), "  You have been promoted to a level %d admin by %s", level, sendername);
but when I do the same with this line it gives me 26 errors again why is it ? please help me guys i really don't get it...
Reply
#10

Send full script lol..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)