make a keypress event work for multiple keys

0 favourites
  • 3 posts
From the Asset Store
Very simple code without excess options (15 events for server and 11 events for client)
  • hey everybody,

    My description is kind of vague, but I will try to explain.

    I have a local-multiplayer game where all characters are controlled via different controls. These controls are stored in their instance variables.

    I have movement and such all worked out, and they function by checking whether a button is currently pressed down. However, the "on button pressed" event which I want to use for attacks functions differently (as expected).

    The issue is that I have multiple characters ("Body" in this case) that all have their own attackKey. When I create an event that listens for an "Body.attackKey" to be pressed, it chooses a random Body and listens only for that specific keypress and only attacks with that specific Body.

    In my movement script I solve this by encapsulating everything in a "For each Body" loop, so that all the references to "Body" reference the same instance. This does not work in this issue because it is a triggered event so it does not work in a loop.

    So to be clear, I want to be using "on key pressed" because I don't want the player to be able to hold the key down to attack automatically.

    I am not really sure how to solve this issue in a non-convoluted way, so I would appreciate any help.

  • You can use "On any key pressed" event, and inside it grab the key code (Keyboard.LastKeyCode) and look up which player it's associated with.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Oh wow, of course that is the solution. What an oversight on my part, turns out working after midnight is not the best for my brain.

    Thanks a lot!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)