360 Plugin - On Key Pressed

For questions about using Classic.

Post » Fri Jul 30, 2010 7:51 pm

Is there a way to make the 360 plugin only recognize the initial press of a button, such as the keyboard plugin's 'on key pressed' behavior? I'm running into a problem with my game's menus. For example, my pause menu. Even if I just tap the 'start' button on my 360 controller, several ticks go by in-game and as a result my pause menu flashes up on screen, then exits back to gameplay, then comes back up.

I hope this makes sense. If not, I will try to offer a better explanation.

Thanks!
B
1
G
2
Posts: 2
Reputation: 629

Post » Fri Jul 30, 2010 9:17 pm

Since the x360 object only has the one condition, you might have to code a workaround.

Say, start a one-second timer on key press and then have your original event ignore that button unless the timer is at 0.
B
2
S
1
G
2
Posts: 35
Reputation: 870

Post » Fri Jul 30, 2010 9:19 pm

I've run into a similar issue before, and I dealt with it by using a variable to keep track of it's state. Suppose that you wanted to rotate a sprite 90 degrees per press to test it out:

[code:5sf9uw9a]+ Xbox360Controller: (1): Start is down
+ System: Is global variable 'StartPressed' Equal to 0
-> System: Set global variable 'StartPressed' to 1
-> Sprite: Rotate 90 degrees counter-clockwise
+ System: Else
-> System: Set global variable 'StartPressed' to 0[/code:5sf9uw9a]

I suppose that you'd need a global or private variable for each button press or multi-button press that you'd want to know the 'pressed' state of.

Note that the else condition is paired with the Start is down condition, and the indented condition is a sub-event of the first condition.
B
3
S
2
G
2
Posts: 187
Reputation: 1,449

Post » Fri Jul 30, 2010 10:30 pm

Thanks for the replies. I was afraid that would be the solution :(.
B
1
G
2
Posts: 2
Reputation: 629

Post » Sat Jul 31, 2010 12:54 am

I ran into this earlier today when trying out the most recent release (xb controller plugin was broken a while ago) and came up with this solution.

I set up so pressing X make the character shoot.

+ Button X is down
- Create object etc etc

This of course creates one instance of the bullet every tick that the button is pressed, not what I want. So I simply added one condition to my event.

+ Button X is down
+ Trigger once
- Create object etc etc

Now it only fires the bullet once, until I let go of the button and press again.
B
73
S
20
G
10
Posts: 524
Reputation: 9,896

Post » Sat Jul 31, 2010 1:51 am

I remember trying that 'trigger once while true' condition first, and found it unreliable in my case. I could not find any obvious reason why, though. Maybe the events were too complicated, and I couldn't spot an error, but I ended up using the method that I mentioned above. That was several versions of Construct ago, though.

If the 'trigger once' works for you, then that that's pretty simple. Just add it to the condition. It does the same thing for you, without the overhead of the extra variables and events.

I have found that 'trigger once' works as expected most of the time when I use it, which is seldom.
B
3
S
2
G
2
Posts: 187
Reputation: 1,449


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests