06.07.2012, 21:40
Hello
I want to load vehicles from a MySQL table. For this I use BlueG MySQL plugin rev. 5 and sscanf 2.6 on Linux. The string from the mysql table is correct, but the splitting goes wrong (In my opinion).
Enum for the vehicle(row):
Code for loading a vehicle
And the output from the server console. Pay attention for the NaN value (The second float should be the first, the third the second and the fourth the third (and then we don't have a third, because the first is NaN):
As you can see, the output should be:
The output fromt he server console:
And I attached a screen from the mysql table in PHPMyAdmin
I don't what happens, is this really a bug in sscanf or did I a very stupid mistake ?
Dudalus
I want to load vehicles from a MySQL table. For this I use BlueG MySQL plugin rev. 5 and sscanf 2.6 on Linux. The string from the mysql table is correct, but the splitting goes wrong (In my opinion).
Enum for the vehicle(row):
Code:
enum vehicleinfo { ID, Status, Plate[10], Model, FractionID, JobID, Noob, Locked, Towed, Tunable, Float:X1, Float:Y1, Float:Z1, Float:A1, Float:X2, Float:Y2, Float:Z2, Float:A2, Owner[30], Key1[30], Key2[30], Color1, Color2, Paintjob, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13 };
Code:
LoadVehicles() { new query[512], string[512]; for(new i = 1; i < MAX_VEHICLES; i++) { format(query,512, "SELECT * FROM Vehicle WHERE ID = '%d'", i); mysql_query(query); mysql_store_result(); if(mysql_num_rows() > 0) { mysql_fetch_row(string); mysql_free_result(); printf("%s", string); sscanf(string, "e<p<|>dds[10]dddddddffffffffs[30]s[30]s[30]ddddddddddddddddd>", Vehicle[i]); if(Vehicle[i][Status]) { new vehicleid = -1; new respawntime = -1; if(Vehicle[i][Noob]) { respawntime = 600000; } if(!Vehicle[i][Towed]) { printf("Model: %d FractionID: %d JobID: %d Noob: %d Locked: %d Towed: %d Tunable: %d", Vehicle[i][Model], Vehicle[i][FractionID], Vehicle[i][JobID], Vehicle[i][Noob], Vehicle[i][Locked], Vehicle[i][Towed], Vehicle[i][Tunable]); printf("X1: %f Y1: %f Z1: %f A1: %f ", Vehicle[i][X1], Vehicle[i][Y1], Vehicle[i][Z1] + 1, Vehicle[i][A1]); vehicleid = CreateVehicle(Vehicle[i][Model], Vehicle[i][X1], Vehicle[i][Y1], Vehicle[i][Z1] + 1, Vehicle[i][A1], Vehicle[i][Color1], Vehicle[i][Color2], respawntime); printf("%d", vehicleid); } else { printf("Towed"); vehicleid = CreateVehicle(Vehicle[i][Model], Vehicle[i][X2], Vehicle[i][Y2], Vehicle[i][Z1] + 1, Vehicle[i][A2], Vehicle[i][Color1], Vehicle[i][Color2], respawntime); } SetVehicleNumberPlate(vehicleid, Vehicle[i][Plate]); VehicleID[vehicleid] = Vehicle[i][ID]; SetVehicleConfiguration(vehicleid); } } } }
Code:
Wrong output: "Nan (At position X1 we have an invalid value)", "1126.530029 (X1, but at position of Y1)", "-1451.319946 (Y1, but at position of Z1)", "15.516900 (Z1, but at position of A1")
Code:
"1126.53 (X1)", "-1452.32 (Y1)", "15.5169 (Z1)", "351.84 "A1"
Code:
[23:36:23] 1|1|Terra|596|44|55|66|77|0|99|1126.53|-1452.32|15.5169|351.84|0|0|0|0|Keiner|Keiner|Keiner|0|1|-1|0|0|0|0|0|0|0|0|0|0|0|0|0|0 [23:36:23] Model: 596 FractionID: 44 JobID: 55 Noob: 66 Locked: 77 Towed: 0 Tunable: 99 [23:36:23] X1: NaN Y1: 1126.530029 Z1: -1451.319946 A1: 15.516900 [23:36:23] 1
I don't what happens, is this really a bug in sscanf or did I a very stupid mistake ?
Dudalus