History

Fixes and PR comments

Brad Davis committed 11 years ago

Commit e39219c1 parent 0063f9a10 files · +69 −29Browse files

Showing the changes to examples/example/scripts/controllerScriptingExamples.js (1 of 10 files). Show all

Unified · Split

examples/example/scripts/controllerScriptingExamples.js+26−12
@@ -11,6 +11,16 @@ · 10 unmodified lines
1111
1212 // Assumes you only have the default keyboard connected
1313
14+function findAction(name) {
15+ var actions = Controller.getAllActions();
16+ for (var i = 0; i < actions.length; i++) {
17+ if (actions[i].actionName == name) {
18+ return i;
19+ }
20+ }
21+ // If the action isn't found, it will default to the first available action
22+ return 0;
23+}
1424
1525
1626 var hydra = Controller.Hardware.Hydra2;
@@ -46,44 +56,48 @@ Controller.resetAllDeviceBindings(); · 29 unmodified lines
4656 // Query all actions
4757 print("All Actions: \n" + Controller.getAllActions());
4858
59+var actionId = findAction("YAW_LEFT")
60+
61+print("Yaw Left action ID: " + actionId)
62+
4963 // Each action stores:
5064 // action: int representation of enum
51−print("Action 5 int: \n" + Controller.getAllActions()[5].action);
65+print("Action int: \n" + Controller.getAllActions()[actionId].action);
5266
5367 // actionName: string representation of enum
54−print("Action 5 name: \n" + Controller.getAllActions()[5].actionName);
68+print("Action name: \n" + Controller.getAllActions()[actionId].actionName);
5569
5670 // inputChannels: list of all inputchannels that control that action
57−print("Action 5 input channels: \n" + Controller.getAllActions()[5].inputChannels + "\n");
71+print("Action input channels: \n" + Controller.getAllActions()[actionId].inputChannels + "\n");
5872
5973
6074 // Each input channel stores:
6175 // action: Action that this InputChannel maps to
62−print("Input channel action: \n" + Controller.getAllActions()[5].inputChannels[0].action);
76+print("Input channel action: \n" + Controller.getAllActions()[actionId].inputChannels[0].action);
6377
6478 // scale: sensitivity of input
65−print("Input channel scale: \n" + Controller.getAllActions()[5].inputChannels[0].scale);
79+print("Input channel scale: \n" + Controller.getAllActions()[actionId].inputChannels[0].scale);
6680
6781 // input and modifier: Inputs
68−print("Input channel input and modifier: \n" + Controller.getAllActions()[5].inputChannels[0].input + "\n" + Controller.getAllActions()[5].inputChannels[0].modifier + "\n");
82+print("Input channel input and modifier: \n" + Controller.getAllActions()[actionId].inputChannels[0].input + "\n" + Controller.getAllActions()[actionId].inputChannels[0].modifier + "\n");
6983
7084
7185 // Each Input stores:
7286 // device: device of input
73−print("Input device: \n" + Controller.getAllActions()[5].inputChannels[0].input.device);
87+print("Input device: \n" + Controller.getAllActions()[actionId].inputChannels[0].input.device);
7488
7589 // channel: channel of input
76−print("Input channel: \n" + Controller.getAllActions()[5].inputChannels[0].input.channel);
90+print("Input channel: \n" + Controller.getAllActions()[actionId].inputChannels[0].input.channel);
7791
7892 // type: type of input (Unknown, Button, Axis, Joint)
79−print("Input type: \n" + Controller.getAllActions()[5].inputChannels[0].input.type);
93+print("Input type: \n" + Controller.getAllActions()[actionId].inputChannels[0].input.type);
8094
8195 // id: id of input
82−print("Input id: \n" + Controller.getAllActions()[5].inputChannels[0].input.id + "\n");
96+print("Input id: \n" + Controller.getAllActions()[actionId].inputChannels[0].input.id + "\n");
8397
8498
8599 // You can get the name of a device from its id
86−print("Device 1 name: \n" + Controller.getDeviceName(Controller.getAllActions()[5].inputChannels[0].input.id));
100+print("Device 1 name: \n" + Controller.getDeviceName(Controller.getAllActions()[actionId].inputChannels[0].input.id));
87101
88102 // You can also get all of a devices input channels
89103 print("Device 1's input channels: \n" + Controller.getAllInputsForDevice(1) + "\n");
@@ -119,7 +133,7 @@ for (i = 0; i < availableInputs.length; i++) { · 29 unmodified lines
119133
120134 // You can modify key bindings by using these avaiable inputs
121135 // This will replace e (up) with 6
122−var e = Controller.getAllActions()[5].inputChannels[0];
136+var e = Controller.getAllActions()[actionId].inputChannels[0];
123137 Controller.removeInputChannel(e);
124138 e.input = availableInputs[6].input;
125139 Controller.addInputChannel(e);