Array index out of bounds error, tried solving, couldn't.
#1

Hello guys.
There's an error on the 81st line:
Quote:

error 001: expected token: "]", but found "-identifier-"
warning 215: expression has no effect
error 001: expected token: ";", but found "]"
error 029: invalid expression, assumed zero
fatal error 107: too many error messages on one line

The 81st line:
pawn Код:
stock CreateTDboxForPlayer(playerid, title[], titlecolor[], const string[1020])
{
    for(new i = 0; i<MAX_TMENUS; i++)
    {
        if(InfoBox[i][mCreated] == false)
        {
            format(InfoBox[i][mString], sizeof(InfoBox[i][mString]), "%s", string); // 81st line !
            format(InfoBox[i][mTitle], sizeof(InfoBox[i][mTitle]), "%s", title);
            format(InfoBox[i][mtColor], sizeof(InfoBox[i][mtColor]), "%s", titlecolor);
            InfoBox[i][mCreated] = 1;
            return i;
        }
        else continue;
    }
    return 0;
}
Enum declaration:
pawn Код:
enum iBox
{
    bool:mCreated,
    mString[1024],
    mTitle[50],
    mtColor[14],
    bool:mShown
}
new InfoBox[MAX_TMENUS][iBox];
Can't figure it out, if you can help, please do !
Reply
#2

Maybe string's length is higher than mString's?
Reply
#3

I tried setting mString's length to 1024 (Max Textdraw string length) and the string's lesser than that, still the same.
Reply
#4

You can't pre-set values like that in the enum. Remove the '= 0's in the enum and this should work.

Additionally I should tell you two things: 1. Bools use "true" and "false" instead of "1" and "0" (Although I think it might work to use 1 and 0 too) 2. Bools are set to false when declaring, unless specified as true, so what you're trying to do isn't even necessary
Reply
#5

I overused my intelligence, thanks ! I'll just reset it onFSinIt/exit. Though I don't need to ! Also, 0 and 1, from what I coded, work as well as true and false. Thanks once again. I am not home currently, I will change the code and let you guys know if it works.
Reply
#6

Hello guys. I have updated my problem, LarzI, it wasn't solved by whatever you said. But thanks for trying.
Reply
#7

pawn Код:
const string[1020]
Is this even valid syntax? Try:

pawn Код:
string[]
Also:
pawn Код:
format(InfoBox[i][mString], sizeof(InfoBox[i][mString]), "%s", string); // 81st line !
            format(InfoBox[i][mTitle], sizeof(InfoBox[i][mTitle]), "%s", title);
            format(InfoBox[i][mtColor], sizeof(InfoBox[i][mtColor]), "%s", titlecolor);
Will give errors aswel, try:

pawn Код:
format(InfoBox[i][mString], 1024, "%s", string); // 81st line !
            format(InfoBox[i][mTitle], 50, "%s", title);
            format(InfoBox[i][mtColor], 14, "%s", titlecolor);
Reply
#8

Quote:
Originally Posted by Sinner
Посмотреть сообщение
pawn Код:
const string[1020]
Is this even valid syntax? Try:

pawn Код:
string[]
Also:
pawn Код:
format(InfoBox[i][mString], sizeof(InfoBox[i][mString]), "%s", string); // 81st line !
            format(InfoBox[i][mTitle], sizeof(InfoBox[i][mTitle]), "%s", title);
            format(InfoBox[i][mtColor], sizeof(InfoBox[i][mtColor]), "%s", titlecolor);
Will give errors aswel, try:

pawn Код:
format(InfoBox[i][mString], 1024, "%s", string); // 81st line !
            format(InfoBox[i][mTitle], 50, "%s", title);
            format(InfoBox[i][mtColor], 14, "%s", titlecolor);
Woops, it's wrong, I know, but I have tried the string[] parameter.
But what you said about sizeof works. I can't believe it. What could have been the reason?
Reply
#9

Quote:
Originally Posted by Rajat_Pawar
Посмотреть сообщение
Woops, it's wrong, I know, but I have tried the string[] parameter.
But what you said about sizeof works. I can't believe it. What could have been the reason?
I'm not sure why it doesn't work for enums, I think because they are not constants.
Reply
#10

Also (I know I am being a bit irritating here)
I am quite new to all directives. Can you see what's wrong here? It returns a "must be a constant error" to me.
pawn Код:
#if strfind(InfoBox[boxid][mString], "~n~", true) > 32

        #error You need to move to the next line on the 33rd char

    #endif
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)