ID:2198714
 
(See the best response by Kats.)


Problem description: I want my players to be able to use diagonals such as .northwest by pressing two keys at the same time such as North+West which will = .northwest


This also applies to other keys like South+East which will = .southeast


How will I go about this? Looking forward to feedback.



Thanks.
Best response
http://www.byond.com/forum/?post=1864794

That's a snippet I wrote a while ago for more responsive pixel movement, if that's what you're looking for. If not, it's still worth taking a look at how I handle movement in 8 directions.

The move[DIR] procs are to be fired on the key-down (NOT KEY HOLD) and the stop[DIR] are fired on key-up.

Mostly efficient and simple to use and understand.
In response to Kats
I think the point Kats was getting at was you should the && operator.

Basically NORTH && EAST is equal to NORTHEAST. So you can do Move(src,NORTH && EAST).

The explanation of why that works a little more complicated but it will get you by.
I don't think that's what I'm looking for dude. I just want my players to be able to click...let's say if they're using a numpad and they click 4 and 8 they'll move .northwest as 4 = west and 8 = north. This would work the same with normal directional keys like up, down, right, left. Thus, pressing up + left would = .northwest or pressing down + right would = .southeast
In response to Dragnon20
You need to use macros. Such as a macro on numpad 9.

I think I just misunderstood.
I need to use macros, eh? Hmm...
How would I go about that? North+West = .northwest
???

I tried that previously but it didn't work.
I'm lost D:
NORTH && EAST is equal to NORTHEAST

No it is not.

NORTH && EAST is equal to EAST.

&& is a logical operator that results with the rightmost value that was reached before the operator short-circuits. If the rightmost operator is non-true, the result is 0.


Binary operators are what you are thinking of:

NORTH | EAST = NORTHEAST:

1|4 = 5

5|4 = 5

That's because:

1 = 0001
4 = 0100
5 = 0101

0001
OR
0100
=
0101
OR
0100
=
0101

Binary OR is what you mean to be giving him advice on, not logical and.
In response to Ter13
Ter13 wrote:
NORTH && EAST is equal to NORTHEAST

No it is not.

NORTH && EAST is equal to EAST.

&& is a logical operator that results with the rightmost value that was reached before the operator short-circuits. If the rightmost operator is non-true, the result is 0.


Binary operators are what you are thinking of:

NORTH | EAST = NORTHEAST:

1|4 = 5

5|4 = 5

That's because:

1 = 0001
4 = 0100
5 = 0101

0001
OR
0100
=
0101
OR
0100
=
0101

Binary OR is what you mean to be giving him advice on, not logical and.

You're right, brain fart. Just got home from work and I'm in no state to be thinking about this.
You're going to need a separate movement check. You have to be able to detect whether buttons are being held down, not just combining two for-all-intents-and-purposes separate events.

For example, when you press the down arrow, you need to be able to keep track that it's being held down in a variable. Each time Move() is called, you can check to see if more than 1 button is being held down.

In a crud example, let's say you have a macro for both the key-up and key-down events for a key.

when DOWN_ARROW is pressed
SOUTH = true;
when DOWN_ARROW is released
SOUTH = false;


Essentially, make a macro for each key up and key down command for an individual key press.

In your actual movement code, it may look something like this in pseudocode
player/Move()
if(SOUTH == true && EAST == true)
move SOUTHEAST;
if(NORTH == true && WEST == true)
move NORTHWEST;
//Do this for each combination of variables


This may be a very inefficient method of handling movement, but it's simple enough for you to understand how event-driven programming works and how to implement something like that into your code.
Try this resource: http://www.byond.com/developer/SuperAntx/SimpleMove

I think it may be closer to what you're looking for.

Be sure to check demo, macros, move-diagonal to see it in action.

Also under demo, make sure you add the var "move_type"

Code:
mob/player
var/move_type


edit: also it has interchangeable option of WASD or Arrow KEYS so make sure you have the right option selected.
Yeah. I finally got it to work.
What did you try btw? Just curious
In response to Mikeche
Mikeche wrote:
Try this resource: http://www.byond.com/developer/SuperAntx/SimpleMove

I think it may be closer to what you're looking for.

Please don't. With due respect to SuperAntx, it's terrible.

If you look at the code, he's using key1, key2, key3, and key4 vars which makes no sense. Where he should be using a simple var that contains active direction bitflags, he has complex if/else logic. It's kind of a mess.

There has been much better movement code produced since then.
It's all good anyway. I got it working with the help of a friend.