History

;) (added semicolons to js example)

Sam Gondelman committed 11 years ago

Commit b1b2d1f1 parent dd12e471 file · +34 −32Browse files

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

Unified · Split

examples/example/scripts/controllerScriptingExamples.js+34−32
@@ -9,86 +9,88 @@ · 8 unmodified lines
9// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html9// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10//10//
11 11
12// Assumes you only have the default keyboard connected
13
12// Resets every device to its default key bindings:14// Resets every device to its default key bindings:
13Controller.resetAllDeviceBindings()15Controller.resetAllDeviceBindings();
14 16
15// Query all actions17// Query all actions
16print("All Actions: \n" + Controller.getAllActions())18print("All Actions: \n" + Controller.getAllActions());
17 19
18// Each action stores:20// Each action stores:
19// action: int representation of enum21// action: int representation of enum
20print("Action 5 int: \n" + Controller.getAllActions()[5].action)22print("Action 5 int: \n" + Controller.getAllActions()[5].action);
21 23
22// actionName: string representation of enum24// actionName: string representation of enum
23print("Action 5 name: \n" + Controller.getAllActions()[5].actionName)25print("Action 5 name: \n" + Controller.getAllActions()[5].actionName);
24 26
25// inputChannels: list of all inputchannels that control that action27// inputChannels: list of all inputchannels that control that action
26print("Action 5 input channels: \n" + Controller.getAllActions()[5].inputChannels + "\n")28print("Action 5 input channels: \n" + Controller.getAllActions()[5].inputChannels + "\n");
27 29
28 30
29// Each input channel stores:31// Each input channel stores:
30// action: Action that this InputChannel maps to32// action: Action that this InputChannel maps to
31print("Input channel action: \n" + Controller.getAllActions()[5].inputChannels[0].action)33print("Input channel action: \n" + Controller.getAllActions()[5].inputChannels[0].action);
32 34
33// scale: sensitivity of input35// scale: sensitivity of input
34print("Input channel scale: \n" + Controller.getAllActions()[5].inputChannels[0].scale)36print("Input channel scale: \n" + Controller.getAllActions()[5].inputChannels[0].scale);
35 37
36// input and modifier: Inputs38// input and modifier: Inputs
37print("Input channel input and modifier: \n" + Controller.getAllActions()[5].inputChannels[0].input + "\n" + Controller.getAllActions()[5].inputChannels[0].modifier + "\n")39print("Input channel input and modifier: \n" + Controller.getAllActions()[5].inputChannels[0].input + "\n" + Controller.getAllActions()[5].inputChannels[0].modifier + "\n");
38 40
39 41
40// Each Input stores:42// Each Input stores:
41// device: device of input43// device: device of input
42print("Input device: \n" + Controller.getAllActions()[5].inputChannels[0].input.device)44print("Input device: \n" + Controller.getAllActions()[5].inputChannels[0].input.device);
43 45
44// channel: channel of input46// channel: channel of input
45print("Input channel: \n" + Controller.getAllActions()[5].inputChannels[0].input.channel)47print("Input channel: \n" + Controller.getAllActions()[5].inputChannels[0].input.channel);
46 48
47// type: type of input (Unknown, Button, Axis, Joint)49// type: type of input (Unknown, Button, Axis, Joint)
48print("Input type: \n" + Controller.getAllActions()[5].inputChannels[0].input.type)50print("Input type: \n" + Controller.getAllActions()[5].inputChannels[0].input.type);
49 51
50// id: id of input52// id: id of input
51print("Input id: \n" + Controller.getAllActions()[5].inputChannels[0].input.id + "\n")53print("Input id: \n" + Controller.getAllActions()[5].inputChannels[0].input.id + "\n");
52 54
53 55
54// You can get the name of a device from its id56// You can get the name of a device from its id
55print("Device 1 name: \n" + Controller.getDeviceName(Controller.getAllActions()[5].inputChannels[0].input.id))57print("Device 1 name: \n" + Controller.getDeviceName(Controller.getAllActions()[5].inputChannels[0].input.id));
56 58
57// You can also get all of a devices input channels59// You can also get all of a devices input channels
58print("Device 1's input channels: \n" + Controller.getAllInputsForDevice(1) + "\n")60print("Device 1's input channels: \n" + Controller.getAllInputsForDevice(1) + "\n");
59 61
60 62
61// Modifying properties:63// Modifying properties:
62// The following code will switch the "w" and "s" key functionality and adjust their scales64// The following code will switch the "w" and "s" key functionality and adjust their scales
63var s = Controller.getAllActions()[0].inputChannels[0]65var s = Controller.getAllActions()[0].inputChannels[0];
64var w = Controller.getAllActions()[1].inputChannels[0]66var w = Controller.getAllActions()[1].inputChannels[0];
65 67
66// You must remove an input controller before modifying it so the old input controller isn't registered anymore68// You must remove an input controller before modifying it so the old input controller isn't registered anymore
67// removeInputChannel and addInputChannel return true if successful, false otherwise69// removeInputChannel and addInputChannel return true if successful, false otherwise
68Controller.removeInputChannel(s)70Controller.removeInputChannel(s);
69Controller.removeInputChannel(w)71Controller.removeInputChannel(w);
70print(s.scale)72print(s.scale);
71s.action = 173s.action = 1;
72s.scale = .0174s.scale = .01;
73 75
74w.action = 076w.action = 0;
75w.scale = 1000077w.scale = 10000;
76Controller.addInputChannel(s)78Controller.addInputChannel(s);
77Controller.addInputChannel(w)79Controller.addInputChannel(w);
78print(s.scale)80print(s.scale);
79 81
80// You can get all the available inputs for any device82// You can get all the available inputs for any device
81// Each AvailableInput has:83// Each AvailableInput has:
82// input: the Input itself84// input: the Input itself
83// inputName: string representing the input85// inputName: string representing the input
84var availableInputs = Controller.getAvailableInputs(1)86var availableInputs = Controller.getAvailableInputs(1);
85for (i = 0; i < availableInputs.length; i++) {87for (i = 0; i < availableInputs.length; i++) {
86 print(availableInputs[i].inputName);88 print(availableInputs[i].inputName);
87}89}
88 90
89// You can modify key bindings by using these avaiable inputs91// You can modify key bindings by using these avaiable inputs
90// This will replace e (up) with 692// This will replace e (up) with 6
91var e = Controller.getAllActions()[5].inputChannels[0]93var e = Controller.getAllActions()[5].inputChannels[0];
92Controller.removeInputChannel(e)94Controller.removeInputChannel(e);
93e.input = availableInputs[6].input95e.input = availableInputs[6].input;
94Controller.addInputChannel(e)96Controller.addInputChannel(e);