Best Practices for multiple controls?

0 favourites
  • 4 posts
From the Asset Store
Best car suspension with spring effect and very cool terrain generation.
  • What's the best practice for organizing your code when you want multiple ways to control the game? For me, I want to be able to use Keyboard(WASD and Arrow Keys), Analog stick on Xbox controller, and Dpad on Xbox Controller.

    I don't want to put all four "LEFT" inputs into each line of code for what should happen when pressing Left. Do I just use one input to make my game, and then later, copy the code three times, into four groups, replacing the relevant inputs, and enabling the group that the user chooses?

    Ideally, I'd like to say, when you press A, LEFT, Dpad Left, or Analog Xaxis -75, simulate a global thing called LEFT. Then, I can write code from there: When global thing LEFT, action action action etc. Obviously, I thought of using a global, but this doesn't seem like a great practice(though I'm very new). Am I wrong?

    So, what's the best/better approach in organizing code for multiple ways to input LEFT?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I'm not sure if this is anywhere close to the best solution, but could you set it up as "left" is a function, and then just have what pressing left does inside the function, and each control button that moves left calls the left function?

    Does that even make sense?

  • Yeah, it makes sense. I kinda looked into functions, but didn't quite understand it, at least in terms of what I'm looking for.

    Just now I did a bid of a mockup using functions and it worked, on the surface...but I still think it's going to get messy when I get into sub events, checking whether Up is also being pressed at the same time as B is released, and such. It's because functions are a one time trigger, which makes me wary. Even now, I can't check for other functions being called, while in a subevent of a On Call Function. So, that's that.

    Something tells me the best thing to do is focus on one control scheme, and then add the others when I'm done with the game.

    Has anyone tried using a Global variables as a control scheme?

    Global text variable as LEFT, RIGHT, UP, DOWN, NOTHING

    Meh, that won't work. What happens with both LEFT and UP are DOWN...Global variables for each button and direction? That's not right.

  • You could use OR block. It also seems that you have fairly complicated control scheme so local variables could maybe keep things a bit cleaner.

    You probably knew this, but if you use any pre made movement behaviors remember to set Default controls to NO.

    Made example.

    Edit: I forgot it is made with r164.2

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