Dashboard Game Controller buttons not updating?

I’m certain the answer to this is simple, but I’ve got a basic panel that has two buttons and a USB game controller hooked up. When either button 1 or 2 on the game controller is pressed, I want the button background in Dashboard to be red. When it’s not pressed, it should be green. I have it working except for the fact that I have to click on “Apply Changes” in the component editor to see the Dashboard buttons update. How do I set it to constantly listen and respond instantly to changes on the game controller? Script is below, thanks in advance for any help!!

/! block id=1114,1130,1115,1131 !/
switch (params.getParam(‘DB-Joystick.1’, ‘params.joy.button.1.mappings.0.value’, 0).getValue())
{
case 0:
ogscript.setStyle(“BUTTONB”, “bg#green;”);
break;
case 1:
ogscript.setStyle(“BUTTONB”, “bg#red;”);
break;
}
/! block id=1134,1133,1135,1136 !/
switch (params.getParam(‘DB-Joystick.1’, ‘params.joy.button.0.mappings.0.value’, 0).getValue())
{
case 0:
ogscript.setStyle(“ButtonA”, “bg#green;”);
break;
case 1:
ogscript.setStyle(“ButtonA”, “bg#red;”);
break;
}
/!!








!!
/
/!!c0a075b8c55e3b386d29ef301a45d0d8!!/







Hi Aaron,

I’ve attached an example grid below, modified from your provided grid. This example grid has been simplified, but the changes here can be adapted to fit your controller parameters and device context.

One way to accomplish what you’re looking for is to attach your existing task to the controller button parameter, and trigger this task onchange and onload:

In the attached panel, I’ve inserted the param ‘params.joy.button.0.mappings.0.value’ (Button 1 from your joystick). The task used to change the colours of ‘ButtonA’ was attached to this parameter. Here, it’s given a tasktype of onchange and onload:

... With this attached task, whenever the value of the parameter changes (e.g. on a button press), the task is triggered, and changes the colour of the button elements accordingly.

In the example panel, an additional button (‘Toggle Controller Button Value’) is used to emulate this parameter value change, but in your case you should be able to change the parameter value by pressing the button on the controller.

Then, you can do the same with ‘params.joy.button.0.mappings.0.value’, attaching its own task to be triggered onchange to change the colour of ‘ButtonB’.

Hopefully this helps, please let me know if you have any further questions!

Example Grid:

Controller Button 1 Not Pressed Controller Button 1 Pressed

/! block id=1134,1133,1135,1136 !/
switch (params.getValue(‘params.joy.button.0.mappings.0.value’, 0))
{
case 0:
ogscript.setStyle(“ButtonA”, “bg#green;”);
break;
case 1:
ogscript.setStyle(“ButtonA”, “bg#red;”);
break;
}
/!!




!!
/
/!!90fe5fa10ceb42dfbe99e3725b14a948!!/

/! block id=1144,1149,1145,1149,1146,1149 !/
if (params.getValue(‘params.joy.button.0.mappings.0.value’, 0) == 0)
{
params.setValue(‘params.joy.button.0.mappings.0.value’, 0, 1)
} else {
params.setValue(‘params.joy.button.0.mappings.0.value’, 0, 0)
}
/!!






!!
/
/!!477cf072634e432b17e92b4b290a35aa!!/

Hi Aaron,

To amend my previous answer and give an easier way to accomplish this, I’ve attached another grid below.

The tag adds the joystick parameter to its oid attribute, so that it can correctly register when this parameter value is changing - such as when the button is pressed down. It will look like this now:

Secondly, the tag was moved to the "DB-Joystick.1" context, where it can be registered to the joystick parameter.

Example Grid:

/! block id=1114,1130,1115,1131 !/
switch (params.getParam(‘DB-Joystick.1’, ‘params.joy.button.1.mappings.0.value’, 0).getValue())
{
case 0:
ogscript.setStyle(“BUTTONB”, “bg#green;”);
break;
case 1:
ogscript.setStyle(“BUTTONB”, “bg#red;”);
break;
}
/! block id=1134,1133,1135,1136 !/
switch (params.getParam(‘DB-Joystick.1’, ‘params.joy.button.0.mappings.0.value’, 0).getValue())
{
case 0:
ogscript.setStyle(“ButtonA”, “bg#green;”);
break;
case 1:
ogscript.setStyle(“ButtonA”, “bg#red;”);
break;
}
/!!








!!
/
/!!c0a075b8c55e3b386d29ef301a45d0d8!!/