MySQL Floats -
SKAzini - 28.02.2013
FIXED
pawn Код:
enum dEnum
{
ID,
Label[128],
Label2[128],
X,
Y,
Z,
I,
VW,
X2,
Y2,
Z2,
I2,
VW2,
};
new Doors[MAX_DOORS][dEnum];
//--------- the above code goes at the top of the script ---------\\
//--------- the code under this goes in OnGameModeInit ---------\\
Doors[l][ID] = strval(field[0]);
format(Doors[l][Label], 128, "%s", field[1]);
format(Doors[l][Label2], 128, "%s", field[2]);
Doors[l][X] = strval(field[3]);
Doors[l][Y] = strval(field[4]);
Doors[l][Z] = strval(field[5]);
Doors[l][I] = strval(field[6]);
Doors[l][VW] = strval(field[7]);
Doors[l][X2] = strval(field[8]);
Doors[l][Y2] = strval(field[9]);
Doors[l][Z2] = strval(field[10]);
Doors[l][I2] = strval(field[11]);
Doors[l][VW2] = strval(field[12]);
format(string, sizeof(string), "%d, %s, %s, %f, %f, %f", Doors[l][ID], Doors[l][Label], Doors[l][Label2], Doors[l][X], Doors[l][Y], Doors[l][Z]); //debug
print(string); //debug
Console outputs Doors[l][X] to be NaN, Doors[l][Y] to 0.000000 aswell as Doors[l][Z], however it loads the ID, Label and Label2 correctly. WTF?
My login system uses floats in the same way, and it works..
Console output:
Код:
0, SFPD, Exit, NaN, 0.000000, 0.000000
The database row looks like this:
Re: MySQL Floats -
Brokenbreaken - 28.02.2013
I think X,Y,Z its float so:
Float:X,
Float:Y,
Float:Z
etc..
Re: MySQL Floats -
Height - 28.02.2013
for fetching float values you must declare the enumerators X,Y and Z as float or Double depending Upon the precision of decimal points. Also for fetching float or double values from MySQL, you need to use mysql_fetch_float() function. otherwise, the decimal point values wont be loaded properly to the variables
Like this as an example
format(playerQuery, sizeof(playerQuery), "SELECT X FROM `tablename` LIMIT 1 ");
mysql_query(playerQuery);
mysql_store_result();
mysql_fetch_float(Doors[l][X]);
mysql_free_result();
Re: MySQL Floats -
SKAzini - 28.02.2013
---
EDIT: Fixed it by changing all the floats inside the enum having the Float: prefix.
pawn Код:
enum dEnum
{
ID,
Label[128],
Label2[128],
Float:X,
Float:Y,
Float:Z,
I,
VW,
Float:X2,
Float:Y2,
Float:Z2,
I2,
VW2,
};
EDIT2: I read your reply once again, seeing that you mentioned the decimals not comming in, yea, it's correct. How do I do this with 6 floats?
EDIT3: This makes the X output to 0.000000:
pawn Код:
mysql_fetch_float(Doors[l][X]);
mysql_free_result();
EDIT4: Fixed by using floatstr instead of strval.
pawn Код:
Doors[l][ID] = strval(field[0]);
format(Doors[l][Label], 128, "%s", field[1]);
format(Doors[l][Label2], 128, "%s", field[2]);
Doors[l][X] = floatstr(field[3]);
Doors[l][Y] = floatstr(field[4]);
Doors[l][Z] = floatstr(field[5]);
Doors[l][I] = strval(field[6]);
Doors[l][VW] = strval(field[7]);
Doors[l][X2] = floatstr(field[8]);
Doors[l][Y2] = floatstr(field[9]);
Doors[l][Z2] = floatstr(field[10]);
Doors[l][I2] = strval(field[11]);
Doors[l][VW2] = strval(field[12]);