ID:1935485
 
(See the best response by Lummox JR.)
Descriptive Problem Summary: Either I'm a complete idiot and did something really wrong, or If() does not seem to detect diagonal directions correctly.

Numbered Steps to Reproduce Problem:

1: Create a moving object
2: When having it move, have an if and else statement for its dir
3: Have the if check if its moving diagonal, or not
4: Watch it always choose the diagonal code, even as the object moves otherwise

Code Snippet (if applicable) to Reproduce Problem:


Expected Results: The if and else statements executes different code according to dir, even when handling diagonals.

Actual Results: The if statement always executes, and never goes to the else when diagonals are involved.

Does the problem occur:
Every time? Or how often? Every time
In other games? Seems so
In other user accounts? Not tested
On other computers? Not tested

When does the problem NOT occur? When you do not involve diagonals

Did the problem NOT occur in any earlier versions? If so, what was the last version that worked? Not sure, maybe someone could test this?

Workarounds: Not sure, though there's probably a few. I just stumbled on to this weird behavior working on something, and it seems to be a BYOND bug so I made this quick test case you can download below that also demonstrates it.

https://www.dropbox.com/s/v5l4cf31bjgxpyi/ Test%20Bug.zip?dl=0


Lummox JR resolved issue (Not a bug)
Best response
These are the kinds of lines that are going wrong in your code:

if(src.dir == SOUTHWEST || NORTHEAST)

That's not how the || operator works. What you would need is actually one of these:

if(dir == SOUTHWEST || dir == NORTHEAST)
// or
if(dir in list(SOUTHWEST, NORTHEAST))

The if statement you used runs if dir==SOUTHWEST is true, or if the NORTHEAST value is true. Since NORTHEAST is 5 and is always true, your if always executes.

Moving this thread to Developer Help.
Ah, curses. I kept thinking it had to be me, and I wondered about the || operator, but when it kept executing no matter what I thought for sure I'd found something.

Oh well, I'll figure something out then. Thanks for the quick response, and sorry for the waste of time!
In response to Toddab503
An easy trick I use to remember operators is highlight the operator and hit F1 (help on). It will bring up the help menu with that operator so you can refresh your memory of the definition of the operator.

I am awful about not remembering the difference between <= and >=. :) (I do a lot of things during the day so my mind isn't always focused on remembering these quirks)
In response to AERProductions
Same here! I'd actually done just that. What threw me off was movement direction specific. I knew they used numbers, or rather I think it's called bit flags or something along those lines. I just didn't realize some of the finer details pertaining to true and false results that Lummox just described.

At any rate, the dir in list method worked just fine, and it was a valuable little lesson. Just one of those random BYOND things that'll fool some programmers at first, I guess.
In response to Toddab503
Yeah. I kind of see Byond like math, there are many ways to do an equation but only a couple of them work properly to get the desired results.

It is a fickle and mysterious thing, 2 people can do the same system and have it come out completely different and I actually like that but it certainly makes the language a bit more confusing for beginners. So many different ways to do the same thing.
In response to Toddab503
I think it always helps to keep in mind that all operators return a value, just like procs.
(a == b) returns true if a equals b, or false.
(a >= b) returns true is a is greater than or equal to b, or false.
(a || b) returns a if a is true-ish, or b if b is true-ish, or false.
(a + b) returns the sum of a and b.
(etc.)
In the above operations, a and b could be another operation. This is how operations are chained.
// this expression
(1+2*3/(4-5)-(6&&7?8:9||10))

// follows these steps
(1 + 2 * 3 / (4-5) - (6 && (7 ? 8 : 9 || 10))) // 4 - 5 = -1
(1 + 2 * 3 / -1 - (6 && (7?8:9||10))) // 7 ? 8 : 9||10 = 8
(1 + 2*3 / -1 - (6 && 8)) // 2*3 = 6
(1 + 6/-1 - (6 && 8)) // 6 / -1 = -6
(1 - 6 - (6&&8)) // 6 && 8 = 8
(1-6 - 8) // 1 - 6 = -5
(-5-8) // -5 - 8 = -13

// to provide this single value
-13
In response to Kaiochao
My brain just weeps when I look at that.
It has a lot to do with being taught 5 different ways to do math (exaggerating to an extent) from multiple different teachers and none of them caring enough to see if any of them stuck with me. None of them did and so I can't really do math very well (I can do number manipulation but if you ask me something like 39 / 5, I can't do it in my head).

:(