SA-MP Forums Archive
floatround in a global variable - 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: floatround in a global variable (/showthread.php?tid=614601)



floatround in a global variable - [DK]Dark_Knight - 10.08.2016

What I'm trying to do is add the following

Код:
#define var1 1000
#define var2 2000
#define var3 0.5

new test[] =
{
    floatround(var1 * var3),
    floatround(var2 * var3)
};
I want to be able to use 'test' anywhere in the script, but obviously this crashes the compiler.
Is there a way to do this?


Re: floatround in a global variable - Vince - 10.08.2016

Arrays can only be initialized with constant values. The result of a function is never a constant. However, the compiler can do constant math and multiplying by 0.5 is the same as dividing by 2.


Re: floatround in a global variable - [DK]Dark_Knight - 10.08.2016

That's what I thought. I'll just make a function to do the same thing.

Код:
Stock func(Id)
{
    Switch(Id)
    {
        Case 0: return floatround(var1 * var3);
        Case 1: return floatround(var2 * var3);
    }
}
Wrote this on my phone real quick. Not sure if formatting is any good.

I could also use divide aswell.


Re: floatround in a global variable - Luicy. - 10.08.2016

Or just use the floatround in instead of func()


Re: floatround in a global variable - PrO.GameR - 10.08.2016

Here's a way to do it so that it's done while compiling instead of a function
PHP код:
#define var1 1000
#define var2 2000
#define var3 5 //splitting var3 into 2 defines to mimic the float
#define var4 10
new test[] =
{
    
var1 var3 var4,
    
var2 var3 var4
}; 
^ that the compiler can do.