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