GM:S 1.4 Using semicolon in-game

Discussion in 'Programming' started by danzibr, Jun 21, 2016.

  1. danzibr

    danzibr Guest

    I have a 2-player game where WASD is used for movement for player 1, and I'd like OKL; to be used for movement for player 2, but I can't get ; to work. vk_semicolon doesn't seem to be built-in, so I tried keyboard_check(ord(';')) and got nothing. Is there a way to get this to work? I'd really rather not use the arrow keys.

    Oh, it's compatible with XBox controllers, and that's how I intend it to be played, but I want to give people the option to use the keyboard, too.
     
  2. GMWolf

    GMWolf aka fel666

    Joined:
    Jun 21, 2016
    Posts:
    3,359
    i think GM uses the ascii codes (but dont quote me on that), so you can try using that ( 59 for ';')
    You can also find out what the code is by adding the following code in the keypress_any key event and pressing the ';' key
    Code:
    show_message(string(keyboard_key));
    as a side note, most web games i have played with 2 players using a WASD configuration would either use the arrow keys or the numpad for player 2.
    But because of different international keyboards and smaller keyboards (missing numpads) I suggest you use keymappings :)
     
  3. rui.rosario

    rui.rosario Guest

    There is a problem I identify with the semicolon key (mainly because it affects me) and that probably is the reason behind the missing vk_semicolon:
    I have a Portuguese keyboard, and if I use keyboard_check(ord(';')) then it gets mapped to the wrong key (I tested this a few months ago, so I don't remember if it gets mapped to a different key right off the Portuguese Layout or when I change to the English Layout and since I tested it some time ago I don't remember all the details).

    Most people use a QWERTY keyboard, and it is guaranteed that the arrow keys, the letters and the number will (to a certain degree) be all in the same place/mapping. However other keys can change due to language purposes (the Portuguese layout for instance has some keys due to accents on words). This means those volatile keys shouldn't be used for the game controls unless you can adapt to the layout in question dynamically.

    Since you use the WASD scheme I would suggest using the IJKL for the second player, as it would also have a similar key placing, only that it would be on the right side of the keyboard instead of the left side.
     
  4. Snail Man

    Snail Man Member

    Joined:
    Jun 20, 2016
    Posts:
    282
    Is the semicolon really necessary, or could you use another key? It seems unreliable with keyboard layouts, and it might be better to just shift all your controls one key to the left.
     
  5. Opticrow

    Opticrow Member

    Joined:
    Jun 21, 2016
    Posts:
    48
    Put this in some step event:
    Code:
    if keyboard_lastkey != 0
       {
       show_message("Keyboard ID: " + string(keyboard_lastkey));
       keyboard_lastkey = 0;
       }
    and then press the ; key. Whatever value it is, put it in your keyboard check :D

    Code:
    keyboard_check( val );
    But don't use vk_ or ord() here, as those are for converting standard keys into that number!
     
  6. Yal

    Yal GMC Memer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    3,460
    Most keyboards for languages with special characters put those characters to the right of P/L/M, so using the semicolon key for something you want to distribute is kinda risky... for instance, on my swedish keyboard, the semicolon key is BELOW K and L, with an Ö key to the right of L. Is there any particular reason you can't use IJKL instead?
     
  7. rui.rosario

    rui.rosario Guest

    On my Portuguese keyboard ';' is located next to M (you need to Shift to write it, because the normal key is ',') and to the right of the L I have Ç
     
  8. BaBiA Game Studio

    BaBiA Game Studio Member

    Joined:
    Jun 20, 2016
    Posts:
    824
    Hang on, if you have to use Shift to get the semi-colon ';' and the normal (un-shifted) key is actually the comma ',' then shouldn't you be checking for the comma in your code instead of the semi-colon?

    Or am I just completely not understanding at all (which is quite possible)?
     
    Opticrow likes this.
  9. Opticrow

    Opticrow Member

    Joined:
    Jun 21, 2016
    Posts:
    48
    Why not just allow the end user to choose their own keybinds? :D
     
    BaBiA Game Studio likes this.
  10. rui.rosario

    rui.rosario Guest

    I'm giving an example of why the use of keys like ';' for game controls should be discouraged, unless some keyboard layout defensive code was taken into action.

    As far as checking for it goes, it would still depend on the layout. Maybe for Portuguese layouts checking for ',' would work, but when you tried it with another it would fail again.
     
  11. BaBiA Game Studio

    BaBiA Game Studio Member

    Joined:
    Jun 20, 2016
    Posts:
    824
    True. I try to stay away from any non-alphanumeric keys for the majority of stuff. Function keys I'll use too but other than those I just won't touch.

    Definitely agree with this.
     
    Opticrow and Snail Man like this.
  12. Nehemek

    Nehemek Member

    Joined:
    Jun 20, 2016
    Posts:
    42
    Yep, the best advice is to have a key bindings menu, for the reason that although letters are more reliable across multiple languages there are still variations of key placement on a single language (see AZERTY keyboard layout which is also for english).
     
  13. icuurd12b42

    icuurd12b42 TMC Founder GMC Elder

    Joined:
    Apr 22, 2016
    Posts:
    1,837
    Opticrow and Zekka like this.
  14. danzibr

    danzibr Guest

    Forgot to check the thread for a bit, all the responses! Thanks everyone. I ended up doing doing keyboard_check(186).

    As for the OKL; business, I more or less need it because on the left hand I have F and G for different attacks, and the right hand has J and H. But really, it's not a crisis. It's meant to be played with controllers anyway.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice