Hey I want to somehow make it so in my game a player can shoot and move at the same time. Right now if they are holding a directional key down, then begin holding the shoot key down at the same time, the movement macro stops and the shoot macro takes over. Then if while still holding the shoot key, they begin also holding a directional key, of course the shoot key will stop activating and they begin moving instead.
I need them to be able to do both at once. Can anyone give me information on how to do this? I want it so if people are holding a directional key and the shoot key at the same time, both macros are doing their thing simultaneously.
Can anyone tell me how this is done?
Hopefully this will also allow me to figure out how to have players move diagonally if they hold for example NORTH and EAST macros at the same time to move NORTHEAST.
http://www.byond.com/developer/Ter13/InputHandler
Take a look at the forum for that library. I include examples of how I implemented a very basic space shooter control scheme using InputHandler. You can do something very similar. |
Ok I will try that out.
But also, could anyone explain to me why my custom code below still cancels out the movement if I press my shoot macro? The code is very simple mob/var/tmp As you can see I have some debug text that tells me when KeyUp() is called. Well, when I press the Shoot macro, it says KeyUp() is called even though I haven't released that arrow key. So then when I do actually release it, KeyUp() is called -again-. So for every KeyDown() event KeyUp() could be called twice if you pressed another macro before actually releasing the arrow key. The good news is that it does let me move diagonally by simply holding the UP+LEFT arrow keys and so on. |
http://i41.tinypic.com/2hdo9kn.jpg
Ignore the "D" macro that is for something else Not only is it sometimes producing more key up events than it does key down events, but sometimes key up events will be inexplicably lost as well when you do certain other things. But that is for another thread I suppose. It would seem that BYOND would need the number of key up events to be EXACTLY the same as the number of key down events once a person completely removes their hands from the keyboard, or the system would be completely borked. Some people's games rely on "what goes down must come up" if you know what I mean. |
Okay, do me a favor and adjust your firing macro to use a similar approach to your movement keys.
In other words, rather than using +REP, use a key-up/key-down pair. I have the feeling that the +REP bit reports a keyup when it shouldn't be. This appears to be a BYOND bug, which might be best reported as well, if this turns out to be the case. I myself, have found a handful of bugs that were quickly fixed with BYOND's key-handling. Pop a solid report in, and I'm sure Lummox can take a look and have it fixed relatively soon. (We have a new beta coming out tomorrow) |
Now that I did what you said and changed the shoot macro from +REP to a key down/up system to begin/end shooting, it works.
So you must be right. I don't like to post more than 1 problem per thread but, there is another problem: 1) hold right arrow key. you are now moving right as expected. 2) begin holding up arrow key as well. you are now moving northeast as expected 3) release right arrow key, continue holding up arrow key. you are now moving north as expected. 4) begin holding left arrow key while still holding north arrow key. you are now INCORRECTLY moving NORTH, when you should be moving northwest. The fact that you began to hold the left arrow key doesn't seem to register. I have this demo prepared if you would like to try it out: http://www.mediafire.com/download/11ls4lxqb9r81rl/Demo.zip It doesn't have the adjusted firing macros though. I will try out your library and hope that fixes the problems. But too tired to implement it right now. |
I don't have the advertised secondary problem with your demo.
I do, however, have the shooting problem. |
I would advise against using +REP, its not stable or reliable in my tests. It will also function differently on each client because it uses the windows setting for repeat-delay per keyboard.
|
Alright, quick update here, I found the problem, and have determined that both issues are not actually bugs.
You are losing KeyUp events due to the procs/verbs not being marked as instant. By default, only one verb can be called from a keybind per tick. Since your system presumes that multiple binds will be active per tick, you need to ensure that the excess commands are called properly by ensuring that the functions are all set to instant. Check out proc/verb settings in the reference for more information. |
Wow thanks that makes perfect sense. It seems to work.
Problem: In the demo I can shoot and move northeast or southeast at the same time just fine, but if I try to move northwest or southwest while shooting, it doesn't work. That has to be a BYOND problem right? Because it can't be a problem with my keyboard since I use up+left and down+left arrow all the time in every 3d game I play and it works there. An engine such as Unity3d has an input system that solves all of these problems and more, I'm not sure why BYOND's leaves so much to be desired. |
Tens of DU wrote:
Wow thanks that makes perfect sense. I don't have time to test if it solves the problems right now but it sounds probable to me. Already did that for you. Seems to solve the problems on my end. |
Tens of DU wrote:
Wow thanks that makes perfect sense. It seems to work. In the interface's macro editor I switched it so that left arrow goes right and right arrow goes left. Yet the problem still only happens with the left arrow combined with north or south, same as before. Right arrow combined with north or south works fine, same as before too. I'm not sure what this means. Is it BYOND's macro handling? |
For example spamming all of the movement keys repeatedly and then after stopping you continue to move for another few seconds. Once beta 1229 comes out, this can be fixed by the developer. Until then, part of what you are noticing is command queueing and network delay. |
Is the whole "+REP causes every other held down macro to register their 'key up' event even though the player is still holding that key down" thing still considered a BYOND bug that needs reported?
|
Add the keys to the list when they are pressed, and remove them when they are released.