Announcement

Collapse
No announcement yet.

How to re-bind keys in-game

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    How to re-bind keys in-game

    Hello guys,
    I'm trying add some polish to my game (which is still far from done itself) so I decided to try to add a feature to allow the player to re-bind their keys directly inside the game (having an end user modify an .ini file for that is just sad).
    I haven't gotten into the menu/scaleform side of things yet but at least now I can re-bind keys from code, and that's what you'll find at my tutorial.

    Interested? have a look at it [here]

    #2
    Great Tut Chosker! Thanks for sharing!

    Comment


      #3
      Thanks! Glad it's of use to somebody.

      I've just edited the tutorial. I removed all of the "how to make the game know when a key is pressed" functionality, and I did this because it makes much more sense to create such a system inside your flash menu, as scaleform blocks input passing through the game anyway.
      therefore the tutorial is now much shorter and easier now you just pass the key you want to bind and the command you want it to do

      Comment


        #4
        With the update it seems very nice, thank you very much for this.
        Just one question, why is the function simulated?

        Comment


          #5
          Originally posted by Chosker View Post
          Thanks! Glad it's of use to somebody.
          Wanted to let you know that I also found this helpful. This is something I've wondered about, I just figured I'd get to it later in the stages of completion of my game/demo. When I saw your post it looked like a good way to investigate this and I thought your tut was easy to understand and within probably less than a minute I was able to identify the function calls that were unknown to me. So totally helpful stuff, I know what I need to know now and I've got your example for reference. Just wanted to say THANKS! its appreciated!

          Comment


            #6
            Yeah thanks! Interesting stuff

            Comment


              #7
              Psykocyber: I honestly have no idea why it's simulated I got into UTPlayerInput and saw that functions there were simulated and decided to trust the code and get on to what I needed instead of wasting time thinking why it was that way

              btw getting the mouse clicks to be recognized in Flash is pretty much impossible (other than the left mouse button) so in the end I had to implement things I had done in the tutorial before I edited them, which is some stuff to make the game detect when a mouse button is pressed, then make my flash menu ignore those keys for a while so they go through

              anyway I'm glad more people make use of it, maybe this is the beginning of the end of those sad jpeg-static 'controls' screens

              Comment


                #8
                I just tried this tutorial out and it worked great!
                Three issues though.

                1) The font you are using for your code is poor. I had the tutorial open on one computer while I followed it on another (at the time it was less work than finding the tutorial again) so instead of copy-pasting the code I read it and typed it in. The font you chose for the code in the tutorial made "BindIndex--" look like "BindIndex-".
                Since I've never used for loops in UnrealScript before I just figured that was the proper syntax. It came up with a compile error, of course, and since I wasn't 100% sure of the spacing used I first spent several minutes checking/testing the spaces I was using in the code. If I didn't have some minor experience with C++ -and happen to recall the syntax for for loops- I might still be trying to figure out what the problem is. It may not sound like much, but remember that most tutorials are made for people that don't know this stuff.

                2) I'm really looking forward to some good examples of how one should implement the function in their code. I can't just put the commands into my script by themselves, they need to be in a function, and that function needs to be called. Since they are exec functions I was able to type the new keyboard bindings into the console during the game, but I don't have any good ideas for any other way to do that. It would probably be worth mentioning this information too, for the sake of people who don't understand much script.
                2a) Perhaps you could also include a nice "reset to defaults" exec command into the tutorial; I imagine just another exec function that calls ChangeInputBinding for a large list of specific bindings. It would not only be useful for the actual UI part that assigns the commands, (in case someone wants a "reset to default" option,) but also could be useful for quick testing of the code. (Have the last part of the tutorial say to play the game and put in the "reset to default" console command.)

                3) Though I doubt this one will apply to many people, the PlayerControl class I made for my project extends from PlayerController, not UTPlayerController or UDKPlayerController. This meant that I couldn't extend myPlayerInput from UTPlayerInput within myPlayerController, since UTPlayerInput is within classes that myPlayerInput was not a child of. But because I don't know what I'm talking about it took me a long while to figure out what the problem was. Some clarification would have been nice, especially since the UDN's public documentation doesn't really give examples about how "within" works.
                In truth I was trying to extend myPlayerInput from UDKPlayerInput because (After chasing through all of the extensions to find what class I should extend it from) I decided I might want those mobile inputs later, so I was forced to either lose those mobile inputs by extending myPlayerInput from PlayerInput, or inherit a bunch of **** I might not want from the UDKPlayerController. Personally I chose the latter but it might be worth it to mention this in the tutorial; there are a number of folks who didn't want to inherit all the properties of the UT games.

                These might not seem like a really complicated or problematic things, but if you're not making the tutorial for people who don't understand this stuff very well, then who are you making the tutorial for?

                PS- Since the function only binds one key at a time, it doesn't seem well-adapted for a UI that doesn't save the configuration until the player clicks "Save changes." You might consider a follow-up tutorial that shows how to handle that possible situation.

                Comment


                  #9
                  1) I actually didn't notice that until now, and it gets worse. if you copy and paste the text it comes out at as "BindIndex-" but then if I go edit the page it clearly says "BindIndex--", must be a problem with WordPress, not the font. sorry about that

                  2) these commands are clearly made to be put in a menu, there would be their actual implementation. however making a menu is a complex task that involves doing a number of stuff in a number of places. I don't have time to write such a tutorial nor do I want to.
                  2a) I might include a "reset" button, but probably not for the tutorial. a reset button would require to save all bindings into a new set of variables at start (as you can't just revert the config file) and re-assign them all as bindings for each key if it's clicked.

                  3) I myself use the UT classes. I'm trying to develop a game by myself, and having to code all the stuff that's already coded in just because there's more than I need sounds like a huge waste of time. wait it doesnt just sound like it, I actually tried extending from the bare classes at first and noticed how much time I was wasting.
                  as I use the UT classes I don't know how the stuff I do would work without them, and I don't have time to find out, sorry.

                  PS) similar to (2a), instead of applying the new binding when its clicked, save it to yet another new set of variables. then if the player clicks "save" apply them as bindings, else just reset the menu texts and go back.


                  to wrap all my answers up I'll explain a little about my intention and target with these tutorials, as I've never properly done it before.
                  my tutorials are quick explanations and pieces of code, not step by step guides. therefore they are targetted at intermediate users because I can't waste time explaining the syntax or why every line of code is there. if there's a typo the user should be able to see it. then again my tutorials are also targetted at intermediate users because of its content: if a beginner programmer tries to code character dismemberment in his game before learning the basics there's clearly something wrong in his approach.

                  my intention here isn't to open everyone's eyes with a tutorial about something complicated and unknown, nor is it to guide them from having nothing to the final implementation. I just try to help people by explaining engine-technical stuff I have found myself that I haven't seen explained anywhere else, and it might make people go ahead and try to implement it now that they have a head start. but it's mostly that, just a head start.
                  and when I say engine-technical I mean something like the stuff needed to bind a key, and just because it's in a dark corner somewhere in the UDK code. but then if you can make a key binding, with enough thought something like reverting shouldn't be a problem at all

                  I hope that clears it out

                  Comment


                    #10
                    Thanks Chosker (From Valencia)

                    Comment


                      #11
                      thanks, really good tutorial

                      Comment


                        #12
                        Great tutorial! Does there have anything about how to reset the key-bindings to default? Should I write a function to read the defaultInput.ini file and reset the keys one by one?

                        Comment


                          #13
                          you could hard-code the defaults one by one and then write a function that replaces all of the bindings for those defaults

                          Comment


                            #14
                            oh... That seems inflexible....I found there has a native function "ResetKeysToDefault" in UDKProfileSettings.uc, I'm wondering whether I can use this....

                            Comment

                            Working...
                            X