MySQL R7 Looping rows of data
#1

I have become a little stumped at a bit of code I am using to attempt to spawn vehicles.

I have pulled it apart to its bare minimum to get a proper response from the code but when I start adding things back in, it stops working.

Here is my code:

Код:
    new rows, fields;
    cache_get_data(rows, fields, connectionHandle);
    
    new tv[1], tvid[1], tvx[1], tvy[1], tvz[1], tvf[1], tvc1[1], tvc2[1];
    
    // loop through all fields
    printf("rows: %d", rows);
    for(new i = 0; i <= rows; i++)
    {
        cache_get_field_content(i, "vid", tv);
        printf("The name of field %d is '%f'", i, strval(tv));
    }
This produces an INFINITE loop for some reason.

If I change:

i <= rows

to

i != rows

the looping stops at line 1!

yet, this is the strange bit. IF I then change the field name from "vid" (which is the actual field name) to "vehid" (another field name) I get 76 results! The next issue is that there should be 1777 results!!!!

Can someone give me a working example of row looping using R7's caching feature? or at least point out what I need to do to get it to work.
Reply
#2

answered my own question:

I was using arrays for every single temporary variable, the idea being the elimination of the need for an inbetween temp variable.

This is how I fixed it:

Код:
    new rows, fields;
    new tmp[20];
    cache_get_data(rows, fields, connectionHandle);
    new tv, tvid, tvx, tvy;
    printf("rows: %d", rows);
    for(new i = 0; i < rows; i++)
    {
        cache_get_field_content(i, "vid", tmp), tv = strval(tmp);
        printf("The name of field %d is '%d'", i, tv);
    }
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)