MySQL Query -
Agent Smith - 11.08.2010
Hello again
I'm having a bit of problem with my script about Faction Spawning:
pawn Код:
new query [256], result[256], Float:X, Float:Y, Float:Z, Float:A;
format(query,256,"SELECT `x`,`y`,`z`,`ang` FROM factions WHERE id = '%d'",playerinfo[playerid][Faction]);
mysql_query(query);
mysql_store_result();
mysql_fetch_row(result);
printf("X: %f", X);
printf("Y: %f", Y);
printf("Z: %f", Z);
sscanf(result,"ffff",X,Y,Z,A);
mysql_free_result();
SetPlayerPos(playerid, X, Y, Z);
SetPlayerFacingAngle(playerid, A);
SetPlayerInterior(playerid, 0);
I've tried debugging the piece of script but it just shows 0.0000000 and so on. Can anyone see where I'm going wrong?
Re: MySQL Query -
JaTochNietDan - 11.08.2010
Well the debugging you've added wouldn't help much since you did it before you even used sscanf to split up the results.
pawn Код:
new query [256], result[256], Float:X, Float:Y, Float:Z, Float:A;
format(query,256,"SELECT `x`,`y`,`z`,`ang` FROM factions WHERE id = '%d'",playerinfo[playerid][Faction]);
mysql_query(query);
mysql_store_result();
mysql_fetch_row(result);
printf("Result contents: %s",result);
sscanf(result,"ffff",X,Y,Z,A);
printf("X: %f", X);
printf("Y: %f", Y);
printf("Z: %f", Z);
mysql_free_result();
SetPlayerPos(playerid, X, Y, Z);
SetPlayerFacingAngle(playerid, A);
SetPlayerInterior(playerid, 0);
That should give you a better idea of wether the query is working or not and what information is coming back
Re: MySQL Query -
Agent Smith - 11.08.2010
Haha, Silly mistake that I made :P
Well the result's that came through are the ones that should but for some reason the results seem to disappear at sscanf(result, "ffff", X,Y,Z,A);
Код:
[20:41:44] Result contents: 1529.6|-1691.2|13.3|0
[20:41:44] X: 0.000000
[20:41:44] Y: 0.000000
[20:41:44] Z: 0.000000
Weird :S
Re: MySQL Query -
JaTochNietDan - 11.08.2010
Quote:
Originally Posted by Samdudes
Haha, Silly mistake that I made :P
Well the result's that came through are the ones that should but for some reason the results seem to disappear at sscanf(result, "ffff", X,Y,Z,A);
Код:
[20:41:44] Result contents: 1529.6|-1691.2|13.3|0
[20:41:44] X: 0.000000
[20:41:44] Y: 0.000000
[20:41:44] Z: 0.000000
Weird :S
|
Try
pawn Код:
sscanf(result, "p|ffff", X,Y,Z,A);
Re: MySQL Query -
Agent Smith - 11.08.2010
Thanks, it worked
Can I ask what difference does that "p|" make?
Re: MySQL Query -
JaTochNietDan - 11.08.2010
It's just changing the delimiter that the sscanf function is using to split the string up. By default it uses spaces, but in your particular result string, it was seperating the results by the '|' character, so to set a new delimiter in sscanf, all you have to do is add p|, telling sscanf to split the string by | and not by spaces
Re: MySQL Query -
Agent Smith - 11.08.2010
Ahh, thanks for that JaTochNietDan

You should introduce a reputation system where you can rate someone for their assistance :P