[19:15:29] Script[gamemodes/BCL-RP.amx]: Run time error 7: "Stack underflow" |
stock LoadSQLPickups()
{
new Field[64];
new Data[512];
new sql[80];
format(sql, sizeof(sql), "SELECT COUNT(*) FROM pickups");
mysql_query(sql);
mysql_store_result();
mysql_fetch_row(Data);
totalpickups = strval(Data);
mysql_free_result();
for (new idx=1; idx<=totalpickups; idx++)
{
format(sql, sizeof(sql), "SELECT * FROM pickups WHERE id=%d", idx);
mysql_query(sql);
mysql_store_result();
if (mysql_num_rows() > 0)
{
mysql_fetch_row(Data);
mysql_fetch_field_row(Field,"message");
strmid(PickupInfo[idx][puMessage],Field,0,strlen(Field),128);
mysql_fetch_field_row(Field,"type");
PickupInfo[idx][puType] = strval(Field);
mysql_fetch_field_row(Field,"model");
PickupInfo[idx][puModel] = strval(Field);
mysql_fetch_field_row(Field,"x");
PickupInfo[idx][puX] = floatstr(Field);
mysql_fetch_field_row(Field,"y");
PickupInfo[idx][puY] = floatstr(Field);
mysql_fetch_field_row(Field,"z");
PickupInfo[idx][puZ] = floatstr(Field);
mysql_free_result();
CreatePickup(PickupInfo[idx][puModel], PickupInfo[idx][puType], PickupInfo[idx][puX], PickupInfo[idx][puY], PickupInfo[idx][puZ]);
}
}
printf("%d pickups loaded from DB", totalpickups);
return 1;
}
mysql_fetch_field_row(Field,"message");
strmid(PickupInfo[idx][puMessage],Field,0,strlen(Field),128);
enum puInfo
{
Float: puX,
Float: puY,
Float: puZ,
puType,
puModel,
puMessage[128]
}; new PickupInfo[MAX_PICKUP+1][puInfo];
mysql_fetch_field_row(PickupInfo[idx][puMessage], "message");
stock LoadSQLPickups()
{
new
x,
totalPickups,
resultString[64]; // Increase if needed.
mysql_query("SELECT * FROM pickups");
mysql_store_result();
totalPickups = mysql_num_rows();
while(mysql_retrieve_row()) {
mysql_get_field("id", result);
x = strval(result);
mysql_get_field("message", PickupInfo[x][puMessage]);
mysql_get_field("type", result);
PickupInfo[x][puType] = strval(result);
mysql_get_field("model", result);
PickupInfo[idx][puModel] = strval(result);
mysql_get_field("x", result);
PickupInfo[idx][puX] = floatstr(result);
mysql_get_field("y", result);
PickupInfo[idx][puY] = floatstr(result);
mysql_get_field("z", result);
PickupInfo[idx][puZ] = floatstr(result);
CreatePickup(PickupInfo[x][puModel], PickupInfo[x][puType], PickupInfo[x][puX], PickupInfo[x][puY], PickupInfo[x][puZ]);
}
mysql_free_result();
return printf("%d pickups loaded from DB", totalPickups);
}
Wow, didn't even see that Calgon. Here I was typing up a large post when it wasn't needed
However, something else I noticed in your code. It seems as if you're wasting an entire row of memory in your array. Array indexes start at 0 and end at size - 1. So you should really change your for loop to something like below else you're just wasting memory. It may only be a matter of bytes now, but you could possibly keep this "habit" and waste a significant amount of memory in larger projects. From: for (new idx = 1; idx<=totalpickups; idx++) To: for (new idx = 0; idx< totalpickups; idx++) |