Retrieving Float Variable issue||sscanf + mysql - 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: Retrieving Float Variable issue||sscanf + mysql (
/showthread.php?tid=368166)
Retrieving Float Variable issue||sscanf + mysql -
Julian2574 - 12.08.2012
Alright as the topic name is, I am trying to retrieve a float through mysql + sscanf 2 using G-Stylez mysql system.
You see every time I retrieve the EntranceX, Y and Z it gives me this
Code:
000.000 000.000 000.000
and I've tried anyway I can to solving this but I can't..
The code:
pawn Code:
enum Building{
bID,
bName,
bInterior,
bxWorld,
beWorld,
Float:bEntX,
Float:bEntY,
Float:bEntZ,
Float:bExitX,
Float:bExitY,
Float:bExitZ
}
new BuildingInfo[MAX_BUILDINGS][Building];
public LoadBuildings()
{
new row[1200];
mysql_query("SELECT * FROM buildings");
mysql_store_result();
new idx=1;
if(mysql_num_rows() > 0){
totalbuildings = mysql_num_rows();
while(mysql_fetch_row(row)){
sscanf(row,"p<|>e<ifffi>",BuildingInfo[idx]);
printf("%f",BuildingInfo[idx][bEntX]); //Debug text
printf("[Building ID]%d[Loaded]",BuildingInfo[idx][bID]);
idx++;
}
}
mysql_free_result();
printf("%d Buildings loaded from database",totalbuildings);
return 1;
}
Debug
Code:
[08:14:46] CMySQLHandler::Query(SELECT * FROM buildings) - Successfully executed.
[08:14:46] >> mysql_store_result( Connection handle: 1 )
[08:14:46] CMySQLHandler::StoreResult() - Result was stored.
[08:14:46] >> mysql_num_rows( Connection handle: 1 )
[08:14:46] CMySQLHandler::NumRows() - Returned 4 row(s)
[08:14:46] >> mysql_num_rows( Connection handle: 1 )
[08:14:46] CMySQLHandler::NumRows() - Returned 4 row(s)
[08:14:46] >> mysql_fetch_row_format( Connection handle: 1 )
[08:14:46] CMySQLHandler::FetchRow() - Return: 2|-2867.16|1066.49|31.5308|1
[08:14:46] >> mysql_fetch_row_format( Connection handle: 1 )
[08:14:46] CMySQLHandler::FetchRow() - Return: 3|-2864.55|1062.38|31.9056|1
[08:14:46] >> mysql_fetch_row_format( Connection handle: 1 )
[08:14:46] CMySQLHandler::FetchRow() - Return: 4|-2856.35|1053.34|32.8544|1
[08:14:46] >> mysql_fetch_row_format( Connection handle: 1 )
[08:14:46] CMySQLHandler::FetchRow() - Return: 5|-2854.77|1044.88|34.4064|1
[08:14:46] >> mysql_fetch_row_format( Connection handle: 1 )
[08:14:46] >> mysql_free_result( Connection handle: 1 )
[08:14:46] CMySQLHandler::FreeResult() - Result was successfully free'd.
Resolved - Had to include the enum into sscanf instead of using enum ..
Resolve code:
pawn Code:
sscanf(row,"p<|>ifffifffi",BuildingInfo[idx][bID],BuildingInfo[idx][bEntX],BuildingInfo[idx][bEntY],BuildingInfo[idx][bEntZ],BuildingInfo[idx][beWorld],BuildingInfo[idx][bExitX],BuildingInfo[idx][bExitY],BuildingInfo[idx][bExitZ], BuildingInfo[idx][bxWorld]);