Need help with format()
#1

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)?
Reply
#2

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

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);
Reply
#4

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);
Reply
#5

@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.
Reply
#6

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


Forum Jump:


Users browsing this thread: 1 Guest(s)