Best Practices for multiple controls?

Get help using Construct 2

Post » Tue Apr 01, 2014 5:46 pm

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?
B
5
Posts: 17
Reputation: 259

Post » Tue Apr 01, 2014 8:46 pm

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?
B
11
S
2
G
1
Posts: 79
Reputation: 842

Post » Wed Apr 02, 2014 6:45 am

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.
B
5
Posts: 17
Reputation: 259

Post » Wed Apr 02, 2014 2:09 pm

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
You do not have the required permissions to view the files attached to this post.
B
34
S
9
G
3
Posts: 517
Reputation: 5,246


Return to How do I....?

Who is online

Users browsing this forum: 8tomo8, brunopalermo and 9 guests