The button didn't detected even though i already set the value to true
Closed this issue · 2 comments
FahrulID commented
This is my code :
`
xbox360SetButtonValue(buttonName, value)
{
let err = null;
if(value !== true && value !== false)
{
err = true;
}
if(!err)
{
switch(buttonName) {
case "X":
this.controller.button.X.setValue(value); // press X button
console.log(`${buttonName}`)
break;
case "Y":
this.controller.button.Y.setValue(value); // press Y button
console.log(`${buttonName}`)
break;
case "A":
this.controller.button.A.setValue(value); // press A button
console.log(`${buttonName}`)
break;
case "B":
this.controller.button.B.setValue(value); // press B button
console.log(`${buttonName}`)
break;
// case "DPAD_UP":
// this.controller.button.DPAD_UP.setValue(value); // press DPAD_UP button
// break;
// case "DPAD_DOWN":
// this.controller.button.DPAD_DOWN.setValue(value); // press DPAD_DOWN button
// break;
// case "DPAD_LEFT":
// this.controller.button.DPAD_LEFT.setValue(value); // press DPAD_LEFT button
// break;
// case "DPAD_RIGHT":
// this.controller.button.DPAD_RIGHT.setValue(value); // press DPAD_RIGHT button
// break;
case "START":
this.controller.button.START.setValue(value); // press START button
break;
case "BACK":
this.controller.button.BACK.setValue(value); // press BACK button
break;
case "LEFT_THUMB":
this.controller.button.LEFT_THUMB.setValue(value); // press LEFT_THUMB button
break;
case "RIGHT_THUMB":
this.controller.button.RIGHT_THUMB.setValue(value); // press RIGHT_THUMB button
break;
case "LEFT_SHOULDER":
this.controller.button.LEFT_SHOULDER.setValue(value); // press LEFT_SHOULDER button
break;
case "RIGHT_SHOULDER":
this.controller.button.RIGHT_SHOULDER.setValue(value); // press RIGHT_SHOULDER button
break;
case "GUIDE":
this.controller.button.GUIDE.setValue(value); // press GUIDE button
break;
default:
err = false;
}
}
return err;
}
`
My code is simple, yet the game or gamepad tester doesn't recognize the input. What did i do wrong ?
FahrulID commented
Dang it, i forgot to call the update, sorry.
jangxx commented
Okay, good to hear that you already figured it out. Two more comments:
-
You can leave the
.updateMode
set to"auto"
and simply not worry about manually callingupdate()
. The performance penalty is close to nonexistent if you're not sending a huge number of inputs per second. -
You can shorten your function to something like this:
xbox360SetButtonValue(buttonName, value) {
if (!(buttonName in this.controller.button)) return false;
this.controller.button[buttonName].setValue(value === true);
console.log(buttonName);
return true;
}