SA-MP Forums Archive
Need help with format() - 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: Need help with format() (/showthread.php?tid=396908)



Need help with format() - scriptit - 02.12.2012

Hello

I have the following code:
Код:
		new Query1[200];
		format(Query1,sizeof(Query1),"UPDATE samp SET Health=%d money=%d WHERE id=%d",GetPlayerHealth(playerid),GetPlayerMoney(playerid),PlayerInfo[playerid][plID]);
		SendClientMessage(playerid,0xFFFFFF,Query1);
		printf("%s",Query1);
		printf("%d",GetPlayerMoney(playerid));
which outputs:
Код:
јPDATE samp SET Health=1 money=1 WHERE id=1
100
Why do I have money=1 in query when I actually have 100 money as seen on printf("%d",GetPlayerMoney(playerid));. Also why do i have that strange symbol in word UPDATE (јPDATE instead of UPDATE)?


Re: Need help with format() - Vince - 02.12.2012

This is now how GetPlayerHealth works. Health is also a float (%f). Lastly, you need commas in between the different fields.


Re: Need help with format() - scriptit - 02.12.2012

edit:

Figured out the correct code:
Код:
		new Query1[200],Float:health,money;
		GetPlayerHealth(playerid,health);
		money = GetPlayerMoney(playerid);
		format(Query1,sizeof(Query1),"UPDATE samp SET Health=%f, money=%d WHERE id=%d",health,money,PlayerInfo[playerid][plID]);
		SendClientMessage(playerid,0xFFFFFF,Query1);
		printf("%s",Query1);
		printf("%d",money);
		printf("%f",health);



Re: Need help with format() - GiamPy. - 02.12.2012

pawn Код:
new szQueryOutput[256];
format(szQueryOutput, sizeof(szQueryOutput),"UPDATE `samp` SET Health = '%d', money = '%d' WHERE `id` = '%d'",GetPlayerHealth(playerid), GetPlayerMoney(playerid), PlayerInfo[playerid][plID]);
SendClientMessage(playerid, 0xFFFFFFAA, szQueryOutput);



Re: Need help with format() - AndreT - 02.12.2012

@GiamPy
Integer values needn't be encapsulated in single quotes, also it is fairly good to stay consistent about your way of writing SQL queries. In your code, aside all the trouble about it not actually working, you switch from one writing schema to another, first having field names without `-quotes, but later on using them.

The issue with the first posted code seems to be a bit awkward to me as well, but it all comes down to GetPlayerHealth native not returning the health float, instead passing it by reference. Also the function requires 2 parameters to start with. scriptit, pay attention to warnings as well in the future.


Re: Need help with format() - GiamPy. - 02.12.2012

My bad, I haven't checked the integer for the health.