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
11 11
12// Assumes you only have the default keyboard connected12// Assumes you only have the default keyboard connected
13 13
14function 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}
14 24
15 25
16var hydra = Controller.Hardware.Hydra2;26var hydra = Controller.Hardware.Hydra2;
@@ -46,44 +56,48 @@ Controller.resetAllDeviceBindings(); · 29 unmodified lines
46// Query all actions56// Query all actions
47print("All Actions: \n" + Controller.getAllActions());57print("All Actions: \n" + Controller.getAllActions());
48 58
59var actionId = findAction("YAW_LEFT")
60
61print("Yaw Left action ID: " + actionId)
62
49// Each action stores:63// Each action stores:
50// action: int representation of enum64// action: int representation of enum
51print("Action 5 int: \n" + Controller.getAllActions()[5].action);65print("Action int: \n" + Controller.getAllActions()[actionId].action);
52 66
53// actionName: string representation of enum67// actionName: string representation of enum
54print("Action 5 name: \n" + Controller.getAllActions()[5].actionName);68print("Action name: \n" + Controller.getAllActions()[actionId].actionName);
55 69
56// inputChannels: list of all inputchannels that control that action70// inputChannels: list of all inputchannels that control that action
57print("Action 5 input channels: \n" + Controller.getAllActions()[5].inputChannels + "\n");71print("Action input channels: \n" + Controller.getAllActions()[actionId].inputChannels + "\n");
58 72
59 73
60// Each input channel stores:74// Each input channel stores:
61// action: Action that this InputChannel maps to75// action: Action that this InputChannel maps to
62print("Input channel action: \n" + Controller.getAllActions()[5].inputChannels[0].action);76print("Input channel action: \n" + Controller.getAllActions()[actionId].inputChannels[0].action);
63 77
64// scale: sensitivity of input78// scale: sensitivity of input
65print("Input channel scale: \n" + Controller.getAllActions()[5].inputChannels[0].scale);79print("Input channel scale: \n" + Controller.getAllActions()[actionId].inputChannels[0].scale);
66 80
67// input and modifier: Inputs81// input and modifier: Inputs
68print("Input channel input and modifier: \n" + Controller.getAllActions()[5].inputChannels[0].input + "\n" + Controller.getAllActions()[5].inputChannels[0].modifier + "\n");82print("Input channel input and modifier: \n" + Controller.getAllActions()[actionId].inputChannels[0].input + "\n" + Controller.getAllActions()[actionId].inputChannels[0].modifier + "\n");
69 83
70 84
71// Each Input stores:85// Each Input stores:
72// device: device of input86// device: device of input
73print("Input device: \n" + Controller.getAllActions()[5].inputChannels[0].input.device);87print("Input device: \n" + Controller.getAllActions()[actionId].inputChannels[0].input.device);
74 88
75// channel: channel of input89// channel: channel of input
76print("Input channel: \n" + Controller.getAllActions()[5].inputChannels[0].input.channel);90print("Input channel: \n" + Controller.getAllActions()[actionId].inputChannels[0].input.channel);
77 91
78// type: type of input (Unknown, Button, Axis, Joint)92// type: type of input (Unknown, Button, Axis, Joint)
79print("Input type: \n" + Controller.getAllActions()[5].inputChannels[0].input.type);93print("Input type: \n" + Controller.getAllActions()[actionId].inputChannels[0].input.type);
80 94
81// id: id of input95// id: id of input
82print("Input id: \n" + Controller.getAllActions()[5].inputChannels[0].input.id + "\n");96print("Input id: \n" + Controller.getAllActions()[actionId].inputChannels[0].input.id + "\n");
83 97
84 98
85// You can get the name of a device from its id99// You can get the name of a device from its id
86print("Device 1 name: \n" + Controller.getDeviceName(Controller.getAllActions()[5].inputChannels[0].input.id));100print("Device 1 name: \n" + Controller.getDeviceName(Controller.getAllActions()[actionId].inputChannels[0].input.id));
87 101
88// You can also get all of a devices input channels102// You can also get all of a devices input channels
89print("Device 1's input channels: \n" + Controller.getAllInputsForDevice(1) + "\n");103print("Device 1's input channels: \n" + Controller.getAllInputsForDevice(1) + "\n");
@@ -119,7 +133,7 @@ for (i = 0; i < availableInputs.length; i++) { · 29 unmodified lines
119 133
120// You can modify key bindings by using these avaiable inputs134// You can modify key bindings by using these avaiable inputs
121// This will replace e (up) with 6135// This will replace e (up) with 6
122var e = Controller.getAllActions()[5].inputChannels[0];136var e = Controller.getAllActions()[actionId].inputChannels[0];
123Controller.removeInputChannel(e);137Controller.removeInputChannel(e);
124e.input = availableInputs[6].input;138e.input = availableInputs[6].input;
125Controller.addInputChannel(e);139Controller.addInputChannel(e);