floatround in a global variable
#1

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

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.
Reply
#3

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.
Reply
#4

Or just use the floatround in instead of func()
Reply
#5

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)