PDA

View Full Version : Too big array?


SKAzini
08/12/2013, 04:18 PM
I added debug sendclientmessage lines. "dialogid 2 debug asd3" debug line doesnt get called, why? Is the field array too big? How to solve it?


SendClientMessage(playerid, -1, "dialogid 2 debug asd1");
new row[128]; // The length of 1 'row' total.
SendClientMessage(playerid, -1, "dialogid 2 debug asd2");
new field[54][128]; // [4] = Amount of fields, [24] = Max length of the bigest field.
SendClientMessage(playerid, -1, "dialogid 2 debug asd3");

mysql_fetch_row_format(row, "|");
SendClientMessage(playerid, -1, "dialogid 2 debug asd4");
explode(row, field, "|");
SendClientMessage(playerid, -1, "dialogid 2 debug asd5");
mysql_free_result();

SendClientMessage(playerid, -1, "dialogid 2 debug 3");

// The field starts here with 1, because the field 'Name' = 0, and we already have the name in a variable.
format(UserStats[playerid][pPassword], 32, "%s", field[2]);
UserStats[playerid][pMoney] = strval(field[3]);
UserStats[playerid][pWarns] = strval(field[4]);
UserStats[playerid][pSkin] = strval(field[5]);
UserStats[playerid][pIP] = floatstr(field[6]);
UserStats[playerid][pGender] = strval(field[7]);
UserStats[playerid][pAge] = strval(field[8]);
UserStats[playerid][pAdmin] = strval(field[9]);
UserStats[playerid][pBanned] = strval(field[10]);
format(UserStats[playerid][pBanReason], 128, "%s", field[11]);
format(UserStats[playerid][pBannedBy], 24, "%s", field[12]);
UserStats[playerid][pX] = floatstr(field[13]);
UserStats[playerid][pY] = floatstr(field[14]);
UserStats[playerid][pZ] = floatstr(field[15]);
UserStats[playerid][pInt] = strval(field[16]);
UserStats[playerid][pVW] = strval(field[17]);
UserStats[playerid][pOwner] = strval(field[19]);
UserStats[playerid][pLevel] = strval(field[20]);
UserStats[playerid][pMinutes] = strval(field[21]);
UserStats[playerid][pHours] = strval(field[22]);
UserStats[playerid][pBank] = strval(field[23]);
UserStats[playerid][pOldAdmin] = strval(field[24]);
UserStats[playerid][pFac] = strval(field[25]);
UserStats[playerid][pFacRank] = strval(field[26]);
UserStats[playerid][pFacLeader] = strval(field[27]);
UserStats[playerid][pWeapon][0] = strval(field[28]);
UserStats[playerid][pWeapon][1] = strval(field[29]);
UserStats[playerid][pWeapon][2] = strval(field[30]);
UserStats[playerid][pWeapon][3] = strval(field[31]);
UserStats[playerid][pWeapon][4] = strval(field[32]);
UserStats[playerid][pWeapon][5] = strval(field[33]);
UserStats[playerid][pWeapon][6] = strval(field[34]);
UserStats[playerid][pWeapon][7] = strval(field[35]);
UserStats[playerid][pWeapon][8] = strval(field[36]);
UserStats[playerid][pWeapon][9] = strval(field[37]);
UserStats[playerid][pWeapon][10] = strval(field[38]);
UserStats[playerid][pWeapon][11] = strval(field[39]);
UserStats[playerid][pWeapon][12] = strval(field[40]);
UserStats[playerid][pWeaponAmmo][0] = strval(field[41]);
UserStats[playerid][pWeaponAmmo][1] = strval(field[42]);
UserStats[playerid][pWeaponAmmo][2] = strval(field[43]);
UserStats[playerid][pWeaponAmmo][3] = strval(field[44]);
UserStats[playerid][pWeaponAmmo][4] = strval(field[45]);
UserStats[playerid][pWeaponAmmo][5] = strval(field[46]);
UserStats[playerid][pWeaponAmmo][6] = strval(field[47]);
UserStats[playerid][pWeaponAmmo][7] = strval(field[48]);
UserStats[playerid][pWeaponAmmo][8] = strval(field[49]);
UserStats[playerid][pWeaponAmmo][9] = strval(field[50]);
UserStats[playerid][pWeaponAmmo][10] = strval(field[51]);
UserStats[playerid][pWeaponAmmo][11] = strval(field[52]);
UserStats[playerid][pWeaponAmmo][12] = strval(field[53]);

Emmet_
08/12/2013, 04:19 PM
a) Do you receive any warnings upon compiling the script?

b) Show us your "explode" function.

SKAzini
08/12/2013, 04:26 PM
a) Do you receive any warnings upon compiling the script?

b) Show us your "explode" function.



Wow, that was fast.


Header size: 25716 bytes
Code size: 2269044 bytes
Data size: 3626860 bytes
Stack/heap size: 16384 bytes; estimated max. usage: unknown, due to recursion
Total requirements: 5938004 bytes



explode(const sSource[], aExplode[][], const sDelimiter[] = " ", iVertices = sizeof aExplode, iLength = sizeof aExplode[]) // Created by Westie
{
new
iNode,
iPointer,
iPrevious = -1,
iDelimiter = strlen(sDelimiter);

while(iNode < iVertices)
{
iPointer = strfind(sSource, sDelimiter, false, iPointer);

if(iPointer == -1)
{
strmid(aExplode[iNode], sSource, iPrevious, strlen(sSource), iLength);
break;
}
else
{
strmid(aExplode[iNode], sSource, iPrevious, iPointer, iLength);
}

iPrevious = (iPointer += iDelimiter);
++iNode;
}
return iPrevious;
}

Emmet_
08/12/2013, 04:31 PM
That array is a bad warning. That warning means that a stack/heap collision will arise, which will overwrite important information on the stack and crash the server.

Place this at the top of the script:


#pragma dynamic 262144


Although it is recommended that you should try and minimize the cell usage on arrays. Global or static arrays are useful for this.

SKAzini
08/12/2013, 04:37 PM
Love you, Emmet. Worked splendit!

Nero_3D
08/12/2013, 04:53 PM
Now he just needs to tell us how he gets 54 fields (the biggest 128 cells long) in one row with 128 character

Emmet_
08/12/2013, 05:03 PM
Now he just needs to tell us how he gets 54 fields (the biggest 128 cells long) in one row with 128 character

Yeah, I've just noticed that! Anyways OP, I would use a while loop for that purpose.


while (mysql_retrieve_row())
{
// ...
}

SKAzini
08/12/2013, 05:09 PM
Yeah, I've just noticed that! Anyways OP, I would use a while loop for that purpose.


while (mysql_retrieve_row())
{
// ...
}


Please explain ???

Emmet_
08/12/2013, 05:16 PM
Here's an example:


new
string[128];

format(string, sizeof(string), "SELECT * FROM `accounts` WHERE `username` = '%s'", ReturnName(playerid));
mysql_query(string);
mysql_store_result();

while (mysql_retrieve_row())
{
mysql_fetch_field_row(string, "Money");
UserStats[playerid][pMoney] = strval(string);

// ...
}
mysql_free_result();

SKAzini
08/12/2013, 05:21 PM
Oooh, I see.. So it gets all fields in a row and puts the value of the field you specify into ex UserStats[playerid][pMoney]? Now I see why the method I used is so inefficient. Thanks again, Emmet!

Am I doing it right?


while (mysql_retrieve_row())
{
mysql_fetch_field_row(string, "pPassword");
format(UserStats[playerid][pPassword], 32, "%s", string);

mysql_fetch_field_row(string, "pMoney");
UserStats[playerid][pMoney] = strval(string);

mysql_fetch_field_row(string, "pWarns");
UserStats[playerid][pWarns] = strval(string);

mysql_fetch_field_row(string, "pSkin");
UserStats[playerid][pSkin] = strval(string);

mysql_fetch_field_row(string, "pIP");
UserStats[playerid][pIP] = strval(string);

mysql_fetch_field_row(string, "pGender");
UserStats[playerid][pGender] = strval(string);

mysql_fetch_field_row(string, "pAge");
UserStats[playerid][pAge] = strval(string);

mysql_fetch_field_row(string, "padmin");
UserStats[playerid][pAdmin] = strval(string);

mysql_fetch_field_row(string, "pBanned");
UserStats[playerid][pBanned] = strval(string);

mysql_fetch_field_row(string, "pBanReason");
format(UserStats[playerid][pBanReason], 128, "%s", string);

mysql_fetch_field_row(string, "pBannedBy");
format(UserStats[playerid][pBannedBy], 32, "%s", string);

mysql_fetch_field_row(string, "pX");
UserStats[playerid][pX] = floatstr(string);

mysql_fetch_field_row(string, "pY");
UserStats[playerid][pY] = floatstr(string);

mysql_fetch_field_row(string, "pZ");
UserStats[playerid][pZ] = floatstr(string);

mysql_fetch_field_row(string, "pInt");
UserStats[playerid][pInt] = strval(string);

mysql_fetch_field_row(string, "pVW");
UserStats[playerid][pVW] = strval(string);

mysql_fetch_field_row(string, "pOwner");
UserStats[playerid][pOwner] = strval(string);

mysql_fetch_field_row(string, "pLevel");
UserStats[playerid][pLevel] = strval(string);

mysql_fetch_field_row(string, "pMinutes");
UserStats[playerid][pMinutes] = strval(string);

mysql_fetch_field_row(string, "pHours");
UserStats[playerid][pHours] = strval(string);

mysql_fetch_field_row(string, "pBank");
UserStats[playerid][pBank] = strval(string);

mysql_fetch_field_row(string, "pOldAdmin");
UserStats[playerid][pOldAdmin] = strval(string);

mysql_fetch_field_row(string, "pFac");
UserStats[playerid][pFac] = strval(string);

mysql_fetch_field_row(string, "pFacRank");
UserStats[playerid][pFacRank] = strval(string);

mysql_fetch_field_row(string, "pFacLeader");
UserStats[playerid][pFacLeader] = strval(string);

for(new i; i < 13; i++)
{
new hi[10];
format(hi, sizeof(hi), "pWeapon%d", i);
mysql_fetch_field_row(string, hi);
UserStats[playerid][pWeapon][i] = strval(string);

mysql_fetch_field_row(string, hi);
UserStats[playerid][pWeaponAmmo][i] = strval(string);
}

}

Emmet_
08/12/2013, 05:40 PM
Yes, nice job.

Also, you should look into threaded queries for more performance and flexibility.