Array and MySQL-Error
#1

Hello.
I have a few errors which I'm unable to fix by no stretch of the imagination.
Код:
error 032: array index out of bounds (variable "haus") // 13x - Everywhere I use haus[i][...]
Here the appreciable part of the code. The errors are mainly in the callback LoadHaus
Hier der relevante Teil des Codes. Hauptsдchlich sind die Fehler im Callback LoadHaus.
pawn Код:
#define MAX_HAUS 350

enum hInfo {
    Float:X,
    Float:Y,
    Float:Z,
    Preis,
    Gebiet[5],
    Besitzer[24],
    KeyID,
    pickup,
    bool:loaded = false
};

new haus[MAX_HAUS][hInfo];

public LoadHaus()
{
    new text[128];
    for(new i=0; i<MAX_HAUS; i++)
    {
        if(haus[i][loaded] == false)
        {
            format(mQuery, 128, "SELECT * FROM haus WHERE ID = %i", i);
            mysql_query(mQuery);
            mysql_store_result();
            if(mysql_num_rows())
            {
                mysql_free_result();
                haus[i][X] = mysql_GetFloat("haus", "X", "ID", i);
                haus[i][Y] = mysql_GetFloat("haus", "Y", "ID", i); // error 032
                haus[i][Z] = mysql_GetFloat("haus", "Z", "ID", i); // error 032
                haus[i][Besitzer] = mysql_GetString("haus", "Besitzer", "ID", i); // error 032
                haus[i][Gebiet] = mysql_GetString("haus", "Gebiet", "ID", i); // error 032
                haus[i][KeyID] = mysql_GetInt("haus", "KeyID", "ID", i); // error 032
                haus[i][Preis] = mysql_GetInt("haus", "Preis", "ID", i); // error 032
                haus[i][loaded] = true;
                if(strlen(haus[i][Besitzer]) > 2) // error 032
                {   // Bewohnt
                    format(text, 128, "- Besitzer: %s -\n- Gebiet: %s -", haus[i][Besitzer], haus[i][Gebiet]); // error 032
                    haus[i][pickup] = CreatePickup(1272, 1, haus[i][X], haus[i][Y], haus[i][Z], -1); // error 032
                    Create3DTextLabel(text, cAQUA, haus[i][X], haus[i][Y], haus[i][Z]+1, 5, 0, 0); // error 032
                }
                else
                {   // Verkдuflich
                    format(text, 128, "- Verkдuflich -\n- Preis: $%i -\n- Gebiet: %s -", haus[i][Preis], haus[i][Gebiet]); // error 032
                    haus[i][pickup] = CreatePickup(1273, 1, haus[i][X], haus[i][Y], haus[i][Z], -1); // error 032
                    Create3DTextLabel(text, cDONE, haus[i][X], haus[i][Y], haus[i][Z]+1, 5, 0, 0); // error 032
                }
            }
        }
        mysql_free_result();
    }
    return 1;
}
Hope you can help me.

Thanks in advance.
Padarom
Reply
#2

Try and change:

pawn Код:
Public LoadHaus()
to:

pawn Код:
stock LoadHaus()
I dont know if that would fix the error or not, but its worth a try.
Reply
#3

The error still remains.
Would anybody have another solution which does the same (load all houses out of a mysql-table)?

If I'd create a new variable for every of these like this:
pawn Код:
new Float:hX[MAX_HAUS], Float:hY[MAX_HAUS], Float:hZ[MAX_HAUS];
It works without errors, but it's pretty messy.
Reply
#4

Try and remove the mysql_free_result above - haus[i][X] = mysql_GetFloat("haus", "X", "ID", i);

Rep if I helped.
Reply
#5

Unfortunately you didn't
Reply
#6

Got it! I made bool:loaded = false. That way I gave loaded a default value. And because one of those enum-variables got a default value it wanted me to give every other variable also a default value.

Booleans ARE false by default. So I could just delete the = false and the error was gone.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)