06.07.2018, 00:24
He is trying to say don't use strings at all, Use implemented functions to extract the integer and fraction, This "probably, I'm not sure" should be faster than using a string
Explained as much as I can below
Having variables is fine, as long as you're using them right, Variables don't take much space or time to make anyways, And sometimes they helps clear things out even if they're unnecessary.
an example for the above code with variables:
Explained as much as I can below
PHP код:
_givePlayerMoney(playerid, Float:amount)
{
ResetPlayerMoney(playerid);
character[playerid][cash] += floatround(amount, floatround_floor); //Gets the integer part of a float(Rounds downwards, Ignoring fractions basically)
character[playerid][coin] += floatround(floatfract(amount)*100, floatround_floor); //Gets the fraction part of the float, multiply it by a hundred to get the first two fractions (You will have to change that if you use more or less than two fractions, or adjust the code) then use the method above to convert it to an integer
SetPlayerMoney(playerid, character[playerid][cash]);
updatePlayerCoinTextDraw(playerid);
return 1;
}
Quote:
I write the code just to see if it works. But it seems long because i create a lot of variables (i don't know if creating a lot of variables like above is needed?) and there're too much steps (strfind, strmid and strval) just to split one short string.
Thank you, this looks shorter (and less variables and may be faster?) than mine. |
an example for the above code with variables:
PHP код:
_givePlayerMoney(playerid, Float:amount)
{
ResetPlayerMoney(playerid);
new cash = floatround(amount, floatround_floor);
new coin = floatround(floatfract(amount)*100, floatround_floor);
character[playerid][cash] += cash;
character[playerid][coin] += coin;
SetPlayerMoney(playerid, character[playerid][cash]);
updatePlayerCoinTextDraw(playerid);
return 1;
}