Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Am I going loopy? constants oddness ..

Jonathan Shaftoe
... the titleless.
Join date: 11 Feb 2005
Posts: 44
03-21-2005 04:01
There was I innocently doing some coding and dealing with rotations for the first time, and so naturally I tried to do this:

float something = -PI_BY_TWO;

But it wouldn't compile. I also tried -(PI_BY_TWO) and 0 - PI_BY_TWO and 0 - (PI_BY_TWO) but no, it simply refused to compile. In the end I had to just write out the value of the constant (-1.5whatever) by hand.

Is this right? Is there a good reason for it? Is it a glitch in the compiler? Have I gone loopy? Should I just be using 3 * PI_BY_TWO instead? Would that have compiled (didn't try it as I only just thought of it now, ahem).

Jonathan
Jeffrey Gomez
Cubed™
Join date: 11 Jun 2004
Posts: 3,522
03-21-2005 04:05
It's right. The interpreter reads your request for the constant "-PI_BY_TWO," which does not exist and is syntatically erroneous besides. You literally have to add the multiplier in there, or if you must, define it yourself.

-3.14159... hell, I forget the rest for NEG_PI. :D

Also, you have to define math operations within a function - can't do it directly as a global. So either you write the raw number in as a global, or start with the operation in state_entry.
_____________________
---
Jonathan Shaftoe
... the titleless.
Join date: 11 Feb 2005
Posts: 44
03-21-2005 04:08
But that's why I tried adding the various other forms with brackets and the like in there. What's the difference, to the compiler, between doing 0 - PI_BY_TWO and 3 * PI_BY_TWO? It's work-aroundable, just seems.. odd.

Ah, you sneakily just edited to add the bit about maths functions, so I'll edit too to make myself not seem so silly ;). So you can do no maths in constant/global declarations at all? Fair enough, though seems strangely limiting as it's something the compiler could easily do.
Jeffrey Gomez
Cubed™
Join date: 11 Jun 2004
Posts: 3,522
03-21-2005 04:10
Wait... you managed to get one of those to compile as a global, but not the other? :eek:

Now that's possibly a bug. Let me test...

Edit: No, no math operations compile as globals. Again, you'll need to do that in state_entry.
_____________________
---
Jonathan Shaftoe
... the titleless.
Join date: 11 Feb 2005
Posts: 44
03-21-2005 04:12
nonono, I didn't try the 3 * .. version, I presume now that'd fail too, I just misinterpretted what you meant by 'adding the multiplier in' - you meant in the body of the code. Just what I was doing was defining a big constant list of rotations, so there is no body of code to do it in, so I have to use the explicit -1.5.. etc thing.

Given they provide PI_BY_TWO and TWOPI as constants, they should have a MINUS_PI_BY_TWO (or THREE_PI_BY_TWO) too, if you ask me.
Sein Edo
Registered User
Join date: 1 Mar 2005
Posts: 3
03-21-2005 09:12
Well.. if

float something = PI_BY_TWO * -1;

is not working. Try:

float something = PI_BY_TWO;
something = -something;
Samhain Broom
Registered User
Join date: 1 Aug 2004
Posts: 298
03-21-2005 09:14
So, it will not compile as a global, but will do well in a state (such as default?)

I mean, is there a problem using -PI_BY_2 directly, or do you have to say that;

variable = (PI_BY_2) * -1

or can you do that either?
_____________________
rm -rf /bin/ladden #beware of geeks bearing grifts
Jonathan Shaftoe
... the titleless.
Join date: 11 Feb 2005
Posts: 44
03-21-2005 09:44
Neither of those (multiplying by -1 or doing a two stage variable setting) will work in constant/global definitions, as they are seemingly not evaluated as well, you can only initialise a global to a constant number, no maths works.

It's a trivial thing to code around in one way or another. It's just irritating, when you're used to being able to do that sort of thing in any other programming language. :)