[Help]I need Simple C# help??

03/15/2015 13:18 iCraziE#1
EDIT :: I FIXED IT.. turns out I was using the "OR" operator instead of the "AND" operator.. lol silly me :D

I needed a little bit of help making a compass feature for a game.

SO, this is my code.. it will only show "E" (east) .. im assuming because for some reason its always seeing the direction as 0 and not updating with the direction.

Code:
long eOffset = this.GameMemory.ReadInt64(gOffset);
                long pOffset = this.GameMemory.ReadInt64(eOffset + 0x22D8);
                pD = this.GameMemory.ReadFloat(pOffset + 0x128);

                if (pD > -0.5 || pD < 0.5 )
                {
                    compass = "E";
                }
                else if (pD > 0.5 || pD < 0.9)
                {
                    compass = "NE";
                }
                else if (pD > 0.9 || pD < 2.0)
                {
                    compass = "N";
                }
                else if (pD > 2.0 || pD < 2.4)
                {
                    compass = "NW";
                }
                else if (pD > 2.4 || pD <= 3.14)
                {
                    compass = "W";
                }
                else if (pD >= -3.14 || pD < -2.4)
                {
                    compass = "W";
                }
                else if (pD > -2.4 || pD < -2.0)
                {
                    compass = "SW";
                }
                else if (pD > -2.0 || pD < -0.9)
                {
                    compass = "S";
                }
                else if (pD > -0.9 || pD < -0.5)
                {
                    compass = "SE";
                }
so that's my terrible attempt at coding. I tried to follow along with what I've seen but I am a complete noob when it comes to this. Can anyone help me know what is wrong here?

Also, I have this declared in the main class

Code:
        public static float pD;

        public string compass; // <----- maybe this is not the right format to set this?
Here is my TextRegion

Code:
TextRegion = new POINT(this.GameWindowRect.Left + 15, this.GameWindowRect.Top + 35);
                if (ShowDirection)
                {
                    DrawText("Direction: " + pD.ToString("F2") + " : " + compass, ref TextRegion, Color.Cyan);
                }
The Direction (pD) is outputting the correct information and updating in my text region.. however no matter what.. the "compass" always show it as east.. meaning its always getting a value of 0, and not the value of (pD) ever y time it changes.

Just for further clarification.. let me give an example of my problem.

In the drawn text, it shows "Direction: 2.10 : E".

This is clearly wrong because according to the math, if the pD ("2.10") is greater than 2.0 and also less than 2.4, it should be displaying "NW" not "E".


Any help or info would be appreciated thanks.
03/15/2015 17:46 warfley#2
Code:
pD > -0.5 || pD < 0.5
this will always be true, use and (&&) not or (||)
03/16/2015 07:27 alpines#3
Quote:
Originally Posted by warfley View Post
Code:
pD > -0.5 || pD < 0.5
this will always be true, use and (&&) not or (||)
Lies mal die 1. Zeile seines Posts.
03/19/2015 22:41 x]vIrus[x#4
please use Math.Pi