Creating Loop but only loops to 7...
#1

Hi guys,

I've never experienced such a strange problem until now, and it's officially left me totally stumped, originally I assumed it was one of the arrays I was using that I perhaps only allocated 7 slots within the 1 dimensional array, so I decided to just printf the current loop integer, in which it finishes at 7...? This makes no sense. Here are screenshots and code to help explain it.


Called at OnGameModeInit()
pawn Код:
format(query, sizeof(query), "SELECT * FROM `bizzactors`");
    mysql_function_query(dbHandle, query, true, "LoadBizzActors", "");
pawn Код:
forward LoadBizzActors();
public LoadBizzActors()
{
    new rows,
        fields,
        temp[100];


    cache_get_data(rows, fields);


    for (new i = 0; i < rows; i++)
    {
        printf("%d", i);

        cache_get_row(i, 0, temp), BizzActors[i][ActorID] = strval(temp);

        cache_get_row(i, 1, temp), BizzActors[i][Actors][i] = strval(temp);

        BizzActors[i][ActX] = cache_get_row_float(i, 2);

        BizzActors[i][ActY] = cache_get_row_float(i, 3);

        BizzActors[i][ActZ] = cache_get_row_float(i, 4);

        BizzActors[i][ActA] = cache_get_row_float(i, 5);

        cache_get_row(i, 6, temp), BizzActors[i][ActorVirtualWorld] = strval(temp);

        cache_get_row(i, 7, temp), BizzActors[i][ActorBizzID] = strval(temp);

        BizzActorNPC[i] = CreateActor(BizzActors[i][Actors][i], BizzActors[i][ActX], BizzActors[i][ActY], BizzActors[i][ActZ], 0.0);

        SetActorFacingAngle(BizzActorNPC[i], BizzActors[i][ActA]);

        SetActorInvulnerable(BizzActorNPC[i], true);

        SetActorVirtualWorld(BizzActorNPC[i], BizzActors[i][ActorVirtualWorld]);


        //printf("BizzActorNPC[%d] %d, %f, %f, %f", i, BizzActors[i][Actors][i], BizzActors[i][ActX], BizzActors[i][ActY], BizzActors[i][ActZ]);
    }

    return 1;
}


The database evidently has more than 7 rows. This is affecting the server now as peoples 'actors' within their businesses are not spawning if they're after row 7.


Extra Info: Being tested on my local machine using XAMPP for Apache and SQL.
Reply
#2

why this? BizzActors[i][Actors][i], add printf("Founded: %d", rows); before of the loop and add Crashdetect for possible crash an in loading data
Reply
#3

Add a printf() that prints the value of "rows". What is that value?
Reply
#4

Quote:
Originally Posted by _Zume
Посмотреть сообщение
why this? BizzActors[i][Actors][i], add printf("Founded: %d", rows); before of the loop and add Crashdetect for possible crash an in loading data
You fixed it! My god I feel like such an amateur. BizzActors[BusinessID][Actors][ActorSlot] was the problem. The ActorSlot was set to 7 as opposed to MAX_BUS_ACTOR which I have defined as 150.

I re-run the compiler, ran the server and it looped upto 9 which is what it was meant to do. Thank you very much for fixing such a simple problem.
As a software developer in real life I always say sometimes fresh eyes can find a problem that the eyes looking at the code all day cannot see!

RealCop! There is someone I've not seen in a while! Anyway I did a print to the values and it's all working now, here is a screenshot just for confirmation.

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)