Somebody helpme with sum of floats? -
OdgFox - 23.01.2018
I need great help with this problem, the one I want to find but I can not find the way (first time I do a system with floats)
Код:
new MarketInventory[][] =
{
{float:0.3500, 10, " Sprunks" },
{float:0.1000, 15, " Cigarrillos" },
{float:0.0100, 5, " Billetes de loteria" }
};
Код:
Dialog:BusinessMarketMenu(playerid, response, listitem, inputtext[])
{
if(!response)return SendClientMessage(playerid, COLOR_WHITE, "Decidiste no comprar en este negocio.");
if(PlayerData[playerid][Money] < MarketInventory[listitem][2])return SendClientMessage(playerid, COLOR_WHITE, ERROR_MONEY);
if(PlayerData[playerid][InventoryWeight] >= MAX_INVENTORY_WEIGHT)return SendClientMessage(playerid, COLOR_WHITE, ERROR_INVENTORY_WEIGHT);
new i = GetNearestBusinessPoint(playerid);
switch(listitem)
{
case 0: // SPRUNKS
{
if(BusinessData[i][Sprunks] == 0)return SendClientMessage(playerid, COLOR_WHITE, "Este negocio no tiene sprunks en su inventario...");
printf("Pesa: %f", MarketInventory[listitem][0]);
printf("Inventario del jugador: %f", PlayerData[playerid][InventoryWeight]);
printf("%f", PlayerData[playerid][InventoryWeight]+MarketInventory[listitem][0]);
}
case 1: // CIGARRILLOS
{
}
}
return true;
}
It should print the data correctly ..
(The weight the player has and the weight of the object) but adding amber in a single print gives another value (as seen at the end)
LOG:
Код:
[20:13:32] Pesa: 0.349999
[20:13:32] Inventario del jugador: 1.000000
[20:13:32] 1051931456.000000 // This is supposed to be the sum of both. (1.349999)
Re: Somebody helpme with sum of floats? -
Misiur - 23.01.2018
pawn Код:
native Float:operator+(Float:oper1, Float:oper2) = floatadd;
This is an operator override for variables tagged with "Float", which is included by default with a_samp (float.inc to be exact). However, you use "float". Those are not the same things. Also, I think if you define a value with a dot, it will be implicitly treated as a variable with Float tag.
See also:
https://sampwiki.blast.hk/wiki/Scripting_Basics#Tags
Re: Somebody helpme with sum of floats? -
OdgFox - 24.01.2018
I had already read about it, but I did not notice that instead of Float I wrote float, now I get this error if I enter it as Float:
Код:
new MarketInventory[][] =
{
{Float:0.350, 10, " Sprunks" },
{Float:0.100, 15, " Cigarrillos" },
{Float:0.010, 5, " Billetes de loteria" }
};
warning 213: tag mismatch
warning 213: tag mismatch
warning 213: tag mismatch
in their respective lines.
Re: Somebody helpme with sum of floats? -
OdgFox - 24.01.2018
I solved the problem, I just had to add the Float: tag.. thanks!
printf("Total: %f", floatadd(PlayerData[playerid][InventoryWeight], Float:MarketInventory[listitem][0]));
Re: Somebody helpme with sum of floats? -
Dayrion - 24.01.2018
You don't need to add "Float:" on a float number. Also, on your array ; you have 3 differents types. You should declare an enumation with those 3 types to make the compiler understand what are you doing. In this enumeration, you must have a variable with a "Float:" tag.
Re: Somebody helpme with sum of floats? -
edyun - 24.01.2018
You should've declared "Float:" on a situation like this where the number is not predefined.
Код:
new Float:X, Float:Y, Float:Z;
---------------------NOT ON----------------
Float:0.3