How to use ‘wasReleased’ with gamepads

I’m working on controller support for my game and one of my scripts has a wasReleased command but when I used the same code but set it up for gamepads and got an error saying
“this.app.gamepads.wasReleased (pc.PAD_1, pc.PAD_FACE_1)” is not a command

if anyone knows why this is happenin and how to fix it I’m all ears.

Sincerely
William Boersma

Have you enabled gamepads in the projects settings?

@yaustar yes I have got everything working except this last thing.

@yaustar HERE is the code https://playcanvas.com/editor/code/719734?tabs=36884907
if you want to take a look

How do you repro the error message?

repro?

How do you reproduce the error message? (eg which scene to load, what actions do I have to do in the app?)

load level 7 - level 11

@yaustar the error went away now it just does nothing

There seems to be an issue with wasPressed that I will look at.

However, moving around with the joystick worked fine for me. If you can’t move around with your controller, try using this site to test your pad: https://gamepad-tester.com/

Fixed in PR: https://github.com/playcanvas/engine/pull/2938

hey @yaustar it still doesn’t work?
can you take another look over my code and see if there is anything wrong.
also like I said before everything works fine with the controller except this.

It’s right here https://playcanvas.com/editor/code/719734?tabs=36884907

@yaustar the error came back

[Launch.js?id=36884907&branchId=b54e717d-51a8-41a2-8464-cdf777c7a322:10]: Uncaught TypeError: this.app.gamepads.wasReleased is not a function

Hi @WilliamBoersma31,

I gave lvl11 a try and it works quite ok, I can move around without getting any error.

2 Likes

if you beat a level then the game crash’s

[Launch.js?id=36884907&branchId=b54e717d-51a8-41a2-8464-cdf777c7a322:10]: this.app.gamepads.wasReleased is not a function

TypeError: this.app.gamepads.wasReleased is not a function
at scriptType.P2Lauch.update (https://launch.playcanvas.com/api/assets/files/Launch.js?id=36884907&branchId=b54e717d-51a8-41a2-8464-cdf777c7a322:10:29)
at ScriptComponent._scriptMethod (https://code.playcanvas.com/playcanvas-stable.dbg.js:59992:19)
at ScriptComponent._onUpdate (https://code.playcanvas.com/playcanvas-stable.dbg.js:60040:11)
at ScriptComponentSystem._callComponentMethod (https://code.playcanvas.com/playcanvas-stable.dbg.js:60606:49)
at ScriptComponentSystem._onUpdate (https://code.playcanvas.com/playcanvas-stable.dbg.js:60623:9)
at Function._helper (https://code.playcanvas.com/playcanvas-stable.dbg.js:41012:12)
at Function.update (https://code.playcanvas.com/playcanvas-stable.dbg.js:41027:9)
at Application.update (https://code.playcanvas.com/playcanvas-stable.dbg.js:66807:20)
at https://code.playcanvas.com/playcanvas-stable.dbg.js:67488:16

There is another forum topic about this problem. I wonder if anything has changed since then.

https://forum.playcanvas.com/t/gamepads-dont-seem-to-use-wasreleased-any-work-around/

Hi @Albertos I tried using that topic’s solution and it did nothing.

If there is still no working wasReleased function for gamepads I think you can do something like below.

var pressed = false;
if (pressed && !this.app.keyboard.isPressed(pc.KEY_0)) {
    pressed = false;
    // Your wasReleased functions here
} 

else if (this.app.keyboard.isPressed(pc.KEY_0)) {
    pressed = true;
    // Normal isPressed functions here
}
2 Likes

@Albertos how do I call pressed would it be

if (pressed) {
‘my code’
}

or

if (pressed) {

}

else {
‘my code’
}