Where is wrong? -
3417512908 - 12.06.2018
I try to make a random float
Код:
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
new Float:rand = random(x+100) + x-100;//error
new Float:rand2 = random(y+100) + y-100;//error
SetPVarFloat(playerid,"diedx",rand);SetPVarFloat(playerid,"diedy",rand2);SetPVarFloat(playerid,"diedz",z);
SetPVarInt(playerid,"diedv",GetPlayerVirtualWorld(playerid));
SetPVarInt(playerid,"loading",1);
And pawno warnings:
Код:
C:\Users\Administrator\Desktop\FantasyLand\gamemodes\FantasyLand.pwn(1898) : warning 213: tag mismatch
C:\Users\Administrator\Desktop\FantasyLand\gamemodes\FantasyLand.pwn(1899) : warning 213: tag mismatch
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase
2 Warnings.
Someone know why? I added "new Float:rand"
Isn`t "new rand"
But still give me warnings
Re: Where is wrong? -
Calisthenics - 12.06.2018
random function accepts only integer as parameter and x/y is not. Use
floatround
Re: Where is wrong? -
Dayrion - 12.06.2018
random take integer as arguemnt, not float so the compiler warns you about that.
Re: Where is wrong? -
3417512908 - 12.06.2018
Quote:
Originally Posted by Calisthenics
random function accepts only integer as parameter and x/y is not. Use floatround
|
Thank!It is useful!
I successfully compiled it
Код:
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
new rand = random(floatround(x,floatround_round)+100) + floatround(x,floatround_round)-100;
new rand2 = random(floatround(y,floatround_round)+100) + floatround(y,floatround_round)-100;
SetPVarFloat(playerid,"diedx",rand);SetPVarFloat(playerid,"diedy",rand2);SetPVarFloat(playerid,"diedz",z);
SetPVarInt(playerid,"diedv",GetPlayerVirtualWorld(playerid));
SetPVarInt(playerid,"loading",1);
Re: Where is wrong? - poppingrose - 12.06.2018
Wait, so how do you use it?
Re: Where is wrong? -
NaS - 12.06.2018
That doesn't look very correct though. Even if it does work, it will not be a true randomized float (it will not be precise).
If you want a real random float you can do that by calculating a random integer between 0 and 1000, convert that number to float and divide it by 1000.0. You'll have a float from 0.0 to 0.999 and can use this as factor for the range you want to randomize.
For example, if you want a random float ranging from 0.0 to a given number (like random(), just as float):
Код:
forward Float:floatrandom(Float:val);
Float:floatrandom(Float:val)
{
return float(random(1000)) / 1000.0 * val;
}
Then you can use this function to calculate a true random float.
Re: Where is wrong? -
Ada32 - 12.06.2018
well it can never be 'truly' random but yea..