SA-MP Forums Archive
Creating Loop but only loops to 7... - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Creating Loop but only loops to 7... (/showthread.php?tid=589055)



Creating Loop but only loops to 7... - LiamM - 14.09.2015

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.


Respuesta: Creating Loop but only loops to 7... - Zume - 15.09.2015

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


Re: Creating Loop but only loops to 7... - Scenario - 15.09.2015

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


Re: Respuesta: Creating Loop but only loops to 7... - LiamM - 15.09.2015

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.