pxt-common-packages 13.2.2 → 13.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/built/common-sim.js +18 -6
- package/libs/base/docs/reference/control/device-long-serial-number.md +26 -0
- package/libs/base/docs/reference/control/device-serial-number.md +1 -0
- package/libs/base/docs/reference/math/constrain.md +36 -0
- package/libs/base/docs/reference/math/map.md +36 -0
- package/libs/color-coded-tilemap/docs/reference/color-coded-tilemap/tile-hit-from.md +81 -0
- package/libs/color-coded-tilemap/tilemap.ts +2 -2
- package/libs/controller/built/debug/binary.js +3 -3
- package/libs/controller---none/built/debug/binary.js +3 -3
- package/libs/core/docs/reference/control/device-dal-version.md +25 -0
- package/libs/core/docs/reference/control/millis.md +25 -0
- package/libs/core/docs/reference/control/pause-until.md +31 -0
- package/libs/core/docs/reference/control/raise-event.md +61 -0
- package/libs/core/docs/reference/control/reset.md +20 -0
- package/libs/core/docs/reference/control/seconds.md +24 -0
- package/libs/core/docs/reference/control.md +17 -0
- package/libs/core/timer.ts +4 -0
- package/libs/core---esp32/dal.d.ts +2 -0
- package/libs/core---esp32s2/dal.d.ts +2 -0
- package/libs/game/built/debug/binary.js +3 -3
- package/libs/game/docs/reference/game/runtime.md +46 -0
- package/libs/light/defaultlights.ts +1 -0
- package/libs/light/defaultlightsoverrides.ts +3 -0
- package/libs/light/docs/reference/light/create-apa102-strip.md +42 -0
- package/libs/light/docs/reference/light/default-strip.md +32 -0
- package/libs/light/docs/reference/light/neopixelstrip/set-gradient.md +31 -0
- package/libs/light/docs/reference/light/neopixelstrip/set-length.md +30 -0
- package/libs/light/docs/reference/light/neopixelstrip/set-mode.md +9 -0
- package/libs/light/docs/reference/light/onboard-strip.md +32 -0
- package/libs/light/docs/reference/light/range.md +61 -0
- package/libs/light/docs/reference/light/set-length.md +29 -0
- package/libs/light/docs/reference/light/set-mode.md +28 -0
- package/libs/light/neopixel.ts +2 -0
- package/libs/mixer/sim/music.ts +18 -6
- package/libs/mouse/docs/reference/mouse/click.md +38 -0
- package/libs/multiplayer/docs/reference/multiplayer/all-players.md +34 -0
- package/libs/multiplayer/docs/reference/multiplayer/is-connected.md +36 -0
- package/libs/multiplayer/player.ts +1 -1
- package/libs/music/docs/reference/music/play-tone.md +8 -3
- package/libs/music/docs/reference/music/set-tone.md +8 -3
- package/libs/net-game/built/debug/binary.js +3 -3
- package/libs/palette/built/debug/binary.js +3 -3
- package/libs/power/power.ts +4 -4
- package/libs/radio/docs/reference/radio/received-packet.md +39 -0
- package/libs/sprite-scaling/built/debug/binary.js +3 -3
- package/libs/storyboard/built/debug/binary.js +3 -3
- package/libs/switch/docs/reference/input/switch-right.md +27 -0
- package/libs/switch/shims.d.ts +2 -1
- package/libs/switch/switch.cpp +1 -0
- package/libs/touch/docs/reference/input/touch/threshold.md +33 -0
- package/package.json +1 -1
|
@@ -6,6 +6,7 @@ namespace light {
|
|
|
6
6
|
*/
|
|
7
7
|
//% blockId="lightstrip_range" block="range from %start|with %length|pixels"
|
|
8
8
|
//% weight=1
|
|
9
|
+
//% help=light/range
|
|
9
10
|
export function range(start: number, length: number): NeoPixelStrip {
|
|
10
11
|
return pixels.range(start, length);
|
|
11
12
|
}
|
|
@@ -17,6 +18,7 @@ namespace light {
|
|
|
17
18
|
//% numleds.defl=30
|
|
18
19
|
//% numleds.shadow=lightLengthPicker
|
|
19
20
|
//% weight=0
|
|
21
|
+
//% help=light/set-length
|
|
20
22
|
export function setLength(numleds: number) {
|
|
21
23
|
light.pixels.setLength(numleds);
|
|
22
24
|
}
|
|
@@ -26,6 +28,7 @@ namespace light {
|
|
|
26
28
|
*/
|
|
27
29
|
//% blockId=lightds_setmode block="set default strip mode to %mode"
|
|
28
30
|
//% weight=0
|
|
31
|
+
//% help=light/set-mode
|
|
29
32
|
export function setMode(mode: NeoPixelMode) {
|
|
30
33
|
light.pixels.setMode(mode);
|
|
31
34
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# create APA102 Strip
|
|
2
|
+
|
|
3
|
+
Create a controller for an addressable APA102 LED strip.
|
|
4
|
+
|
|
5
|
+
```sig
|
|
6
|
+
light.createAPA102Strip();
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
When you connect a APA102 pixel strip to your @boardname@, you have to give your program a way
|
|
10
|
+
to work with it. You tell your program that there is a pixel strip you want to use with
|
|
11
|
+
``||create apa102 strip||``.
|
|
12
|
+
|
|
13
|
+
To use ``||create apa102 strip||``, you need to know which pins the strip is attached to for data and clock signals, and
|
|
14
|
+
how many pixels (LEDs) are on the strip. Also, some pixel strips have different types LEDs.
|
|
15
|
+
If you know the exact type, you can set it in the pixel mode.
|
|
16
|
+
|
|
17
|
+
## Parameters
|
|
18
|
+
|
|
19
|
+
* **dataPin**: [DigitalInOutPin](/reference/pins), the pin where the neopixel strip is connected for data.
|
|
20
|
+
* **clkPin**: [DigitalInOutPin](/reference/pins), the pin where the neopixel strip is connected for the clock signal.
|
|
21
|
+
* **numleds**: the [number](/types/number) of LEDs in the strip, such as: 10, 30, 60, or 64.
|
|
22
|
+
|
|
23
|
+
## Returns
|
|
24
|
+
|
|
25
|
+
* a new **NeoPixelStrip** controller for the neopixels on a APA102 strip connected to the board.
|
|
26
|
+
|
|
27
|
+
## Example
|
|
28
|
+
|
|
29
|
+
Connect a APA102 pixel strip to pind `A1` and `A2`. Make all pixels light up `green`.
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
const strip = light.createStrip(pins.A1, pins.A2, 40);
|
|
33
|
+
strip.setAll(0x00ff00)
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## See Also
|
|
37
|
+
|
|
38
|
+
[range](/reference/light/neopixelstrip/range), [set mode](/reference/light/neopixelstrip/set-mode)
|
|
39
|
+
|
|
40
|
+
```package
|
|
41
|
+
light
|
|
42
|
+
```
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# create Strip
|
|
2
|
+
|
|
3
|
+
Get a controller for the default programmable LED strip.
|
|
4
|
+
|
|
5
|
+
```sig
|
|
6
|
+
light.defaultStrip();
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
The default LED strip is either a strip that is onboard or one that is connected to the board but is set as the default.
|
|
10
|
+
|
|
11
|
+
## Returns
|
|
12
|
+
|
|
13
|
+
* a new **NeoPixelStrip** controller for the default neopixel strip connected to or existing on the board.
|
|
14
|
+
|
|
15
|
+
## Example
|
|
16
|
+
|
|
17
|
+
Get the default pixel strip for the board. Make all pixels light up `green`.
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
const strip = light.defaultStrip( );
|
|
21
|
+
strip.setAll(0x00ff00)
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## See also
|
|
25
|
+
|
|
26
|
+
[onboard strip](/reference/light/neopixelstrip/onboard-strip),
|
|
27
|
+
[range](/reference/light/neopixelstrip/range),
|
|
28
|
+
[set mode](/reference/light/neopixelstrip/set-mode)
|
|
29
|
+
|
|
30
|
+
```package
|
|
31
|
+
light
|
|
32
|
+
```
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# set Gradient
|
|
2
|
+
|
|
3
|
+
Set a gradient between two RGB colors.
|
|
4
|
+
|
|
5
|
+
```sig
|
|
6
|
+
light.createStrip().setGradient(0, 0)
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
The default color gradient for a LED strip is `black` to `white` which is between `0x000000` and `0xffffff` in RGB values. you change that gradient by selecting two other colors to begin and end the gradient range.
|
|
10
|
+
|
|
11
|
+
## Parameters
|
|
12
|
+
|
|
13
|
+
* **startColor**: a [number](/types/number) that is an RGB value for the gradient starting color.
|
|
14
|
+
* **endColor**: a [number](/types/number) that is an RGB value for the gradient ending color.
|
|
15
|
+
|
|
16
|
+
## Example
|
|
17
|
+
|
|
18
|
+
Set a strip color gradient between `blue` and `red`.
|
|
19
|
+
|
|
20
|
+
```blocks
|
|
21
|
+
let strip = light.createStrip()
|
|
22
|
+
strip.setGradient(0x0000cc, 0x880000)
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## See Also
|
|
26
|
+
|
|
27
|
+
[pixel color](/reference/light/neopixelstrip/pixel-color), [rgb](/reference/light/rgb)
|
|
28
|
+
|
|
29
|
+
```package
|
|
30
|
+
light
|
|
31
|
+
```
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# set Length
|
|
2
|
+
|
|
3
|
+
Set the number of LEDs to use in a NeoPixel strip.
|
|
4
|
+
|
|
5
|
+
```sig
|
|
6
|
+
light.createStrip().setLength(1)
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
The strip will have a maximum length of addressable LEDs. You can set it to have a length less than or equal to the maximum length. Nothing will happen to any LEDs beyond this length if attempt to control is made.
|
|
10
|
+
|
|
11
|
+
## Parameters
|
|
12
|
+
|
|
13
|
+
* **numLeds**: a [number](/types/number) that is the current length to set for the LED strip.
|
|
14
|
+
|
|
15
|
+
## Example
|
|
16
|
+
|
|
17
|
+
Set the LED strip length to `8`.
|
|
18
|
+
|
|
19
|
+
```blocks
|
|
20
|
+
let strip = light.createStrip()
|
|
21
|
+
strip.setLength(8)
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
[length](/reference/light/neopixelstrip/length)
|
|
25
|
+
|
|
26
|
+
```package
|
|
27
|
+
light
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
|
|
@@ -13,6 +13,15 @@ Some LED strips also have a white LED (``NeoPixelMode.RGBW``).
|
|
|
13
13
|
|
|
14
14
|
* **mode**: the desired mode
|
|
15
15
|
|
|
16
|
+
## Example
|
|
17
|
+
|
|
18
|
+
Set the mode of a NeoPixel LED strip to `RGBW`.
|
|
19
|
+
|
|
20
|
+
```blocks
|
|
21
|
+
let strip = light.createStrip()
|
|
22
|
+
strip.setMode(NeoPixelMode.RGBW)
|
|
23
|
+
```
|
|
24
|
+
|
|
16
25
|
```package
|
|
17
26
|
light
|
|
18
27
|
```
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# onboard Strip
|
|
2
|
+
|
|
3
|
+
Get a controller for the onboard programmable LED strip.
|
|
4
|
+
|
|
5
|
+
```sig
|
|
6
|
+
light.onboardStrip();
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
The onboard LED strip is a strip exits on the board. It is also usually set as the [default strip](/reference/light/neopixelstrip/default-strip).
|
|
10
|
+
|
|
11
|
+
## Returns
|
|
12
|
+
|
|
13
|
+
* a new **NeoPixelStrip** controller for the onboard neopixel strip.
|
|
14
|
+
|
|
15
|
+
## Example
|
|
16
|
+
|
|
17
|
+
Get the onboard pixel strip for the board. Make all pixels light up `green`.
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
const strip = light.onboardStrip( );
|
|
21
|
+
strip.setAll(0x00ff00)
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## See also
|
|
25
|
+
|
|
26
|
+
[default strip](/reference/light/neopixelstrip/default-strip),
|
|
27
|
+
[range](/reference/light/neopixelstrip/range),
|
|
28
|
+
[set mode](/reference/light/neopixelstrip/set-mode)
|
|
29
|
+
|
|
30
|
+
```package
|
|
31
|
+
light
|
|
32
|
+
```
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# range
|
|
2
|
+
|
|
3
|
+
Create a new, smaller pixel strip from part of the default pixel strip.
|
|
4
|
+
|
|
5
|
+
```sig
|
|
6
|
+
light.createStrip().range(0, 4)
|
|
7
|
+
```
|
|
8
|
+
The new pixel strip is a smaller, _virtual_, strip with some or all of the pixels
|
|
9
|
+
from the current, or original, strip. You can use **range** to make new mini strips from
|
|
10
|
+
one larger strip for use in more complex light effects.
|
|
11
|
+
|
|
12
|
+
If you have a pixel strip with 10 pixels, you can make 2 new _virtual_ strips by giving
|
|
13
|
+
the new strips 5 pixels each. An example of this is something like:
|
|
14
|
+
|
|
15
|
+
```block
|
|
16
|
+
let strip0 = light.createStrip()
|
|
17
|
+
let strip1 = strip0.range(0, 5)
|
|
18
|
+
let strip2 = strip0.range(5, 5)
|
|
19
|
+
```
|
|
20
|
+
You can use these new pixels strips by themselves with their own light actions:
|
|
21
|
+
|
|
22
|
+
```blocks
|
|
23
|
+
let strip1 = light.range(0, 5)
|
|
24
|
+
let strip2 = light.range(5, 5)
|
|
25
|
+
strip1.setAll(0xffff00)
|
|
26
|
+
strip2.setPixelColor(0, 0xff0000)
|
|
27
|
+
```
|
|
28
|
+
The original strip has a `red` pixel at pixel spot `5` but it's at pixel spot `0` for
|
|
29
|
+
the new virtual strip called `strip2`.
|
|
30
|
+
|
|
31
|
+
## Parameters
|
|
32
|
+
|
|
33
|
+
* **start**: the pixel position where the new pixel strip starts at, such as 5
|
|
34
|
+
* **length**: the amount of pixels the new pixel strip will have, like: 10
|
|
35
|
+
|
|
36
|
+
## Returns
|
|
37
|
+
|
|
38
|
+
* A new pixel strip created from the current pixel strip, with some or all of its pixels.
|
|
39
|
+
|
|
40
|
+
## Example
|
|
41
|
+
|
|
42
|
+
Make a smaller strip from the default pixel strip. Shift an `orange` pixel from the beginning
|
|
43
|
+
of the new pixel strip to its end.
|
|
44
|
+
|
|
45
|
+
```blocks
|
|
46
|
+
let smallStrip = light.range(0, 4)
|
|
47
|
+
smallStrip.setPixelColor(0, 0xff0000)
|
|
48
|
+
for (let i = 0; i < smallStrip.length() - 1; i++) {
|
|
49
|
+
pause(500)
|
|
50
|
+
smallStrip.move(LightMove.Shift, 1)
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
## See also
|
|
54
|
+
|
|
55
|
+
[default strip](/reference/light/default-strip)
|
|
56
|
+
|
|
57
|
+
```package
|
|
58
|
+
light
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# set Length
|
|
2
|
+
|
|
3
|
+
Set the number of LEDs to use in the default NeoPixel strip.
|
|
4
|
+
|
|
5
|
+
```sig
|
|
6
|
+
light.defaultStrip().setLength(1)
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
The default strip will have a maximum length of addressable LEDs. You can set it to have a length less than or equal to the maximum length. Nothing will happen to any LEDs beyond this length if attempt to control is made.
|
|
10
|
+
|
|
11
|
+
## Parameters
|
|
12
|
+
|
|
13
|
+
* **numLeds**: a [number](/types/number) that is the current length to set for the default LED strip.
|
|
14
|
+
|
|
15
|
+
## Example
|
|
16
|
+
|
|
17
|
+
Set the default LED strip length to `8`.
|
|
18
|
+
|
|
19
|
+
```blocks
|
|
20
|
+
light.setLength(8)
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
[length](/reference/light/range)
|
|
24
|
+
|
|
25
|
+
```package
|
|
26
|
+
light
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# set Mode
|
|
2
|
+
|
|
3
|
+
Sets the color encoding mode for the default light strip.
|
|
4
|
+
|
|
5
|
+
```sig
|
|
6
|
+
light.defaultStrip().setMode(NeoPixelMode.RGB)
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Most light strips use the Green Red Blue encoding (``NeoPixelMode.RGB``), some use Red Green Blue (``NeoPixelMode.RGB_RGB``).
|
|
10
|
+
Some LED strips also have a white LED (``NeoPixelMode.RGBW``).
|
|
11
|
+
|
|
12
|
+
## Parameters
|
|
13
|
+
|
|
14
|
+
* **mode**: the desired mode
|
|
15
|
+
|
|
16
|
+
## Example
|
|
17
|
+
|
|
18
|
+
Set the mode of the default LED strip to `RGBW`.
|
|
19
|
+
|
|
20
|
+
```blocks
|
|
21
|
+
light.setMode(NeoPixelMode.RGBW)
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
```package
|
|
25
|
+
light
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
|
package/libs/light/neopixel.ts
CHANGED
|
@@ -163,6 +163,7 @@ namespace light {
|
|
|
163
163
|
//% blockId=lightsetgradient block="set %strip gradient from %startColor=colorNumberPicker to %endColor=colorNumberPicker"
|
|
164
164
|
//% weight=79 blockGap=8
|
|
165
165
|
//% group="More" advanced=true
|
|
166
|
+
//% help=light/neopixelstrip/set-gradient
|
|
166
167
|
setGradient(startColor: number, endColor: number) {
|
|
167
168
|
const sr = color.unpackR(startColor);
|
|
168
169
|
const sg = color.unpackG(startColor);
|
|
@@ -857,6 +858,7 @@ namespace light {
|
|
|
857
858
|
//% weight=1 blockGap=8
|
|
858
859
|
//% length.shadow=lightLengthPicker
|
|
859
860
|
//% group="Configuration" advanced=true
|
|
861
|
+
//% help=light/neopixelstrip/set-length
|
|
860
862
|
setLength(numleds: number): void {
|
|
861
863
|
const n = Math.max(0, numleds | 0);
|
|
862
864
|
// lazy update
|
package/libs/mixer/sim/music.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
namespace pxsim.music {
|
|
2
2
|
export function playInstructions(b: RefBuffer) {
|
|
3
|
+
setupOnStopAll();
|
|
3
4
|
return AudioContextManager.playInstructionsAsync(b.data)
|
|
4
5
|
}
|
|
5
6
|
|
|
6
7
|
export function queuePlayInstructions(when: number, b: RefBuffer) {
|
|
8
|
+
setupOnStopAll();
|
|
7
9
|
AudioContextManager.queuePlayInstructions(when, b)
|
|
8
10
|
}
|
|
9
11
|
|
|
@@ -32,17 +34,27 @@ namespace pxsim.music {
|
|
|
32
34
|
|
|
33
35
|
let sequencers: SequencerWithId[];
|
|
34
36
|
let nextSequencerId = 0;
|
|
37
|
+
let onStopAllSetup = false;
|
|
35
38
|
|
|
36
|
-
|
|
37
|
-
if (!
|
|
39
|
+
function setupOnStopAll() {
|
|
40
|
+
if (!onStopAllSetup) {
|
|
41
|
+
onStopAllSetup = true;
|
|
38
42
|
pxsim.AudioContextManager.onStopAll(() => {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
seq
|
|
43
|
+
AudioContextManager.muteAllChannels();
|
|
44
|
+
if (sequencers) {
|
|
45
|
+
for (const seq of sequencers) {
|
|
46
|
+
seq.sequencer.stop();
|
|
47
|
+
seq.sequencer.dispose();
|
|
48
|
+
}
|
|
49
|
+
sequencers = [];
|
|
42
50
|
}
|
|
43
|
-
sequencers = [];
|
|
44
51
|
})
|
|
52
|
+
}
|
|
53
|
+
}
|
|
45
54
|
|
|
55
|
+
export async function _createSequencer(): Promise<number> {
|
|
56
|
+
setupOnStopAll();
|
|
57
|
+
if (!sequencers) {
|
|
46
58
|
sequencers = [];
|
|
47
59
|
}
|
|
48
60
|
const res = {
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# click
|
|
2
|
+
|
|
3
|
+
Emulate a mouse button click.
|
|
4
|
+
|
|
5
|
+
```sig
|
|
6
|
+
mouse.click(MouseButton.Left)
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
A mouse button click is a rapid sequence of button `on` and `off` events. Using **click()** will simulate the two as one action.
|
|
10
|
+
|
|
11
|
+
## ~ hint
|
|
12
|
+
|
|
13
|
+
The @boardname@ needs a connection to a computer or other host device with a USB cable in order to emulate mouse actions. This function doesn't work in the simulator.
|
|
14
|
+
|
|
15
|
+
## ~
|
|
16
|
+
|
|
17
|
+
## Parameters
|
|
18
|
+
|
|
19
|
+
* **button**: the identifier of the button to emulate a mouse click for: `left`, `right`, or `middle`.
|
|
20
|
+
|
|
21
|
+
## Example #example
|
|
22
|
+
|
|
23
|
+
Send a mouse button right-click to a computer that is connected to the @boardname@.
|
|
24
|
+
|
|
25
|
+
```blocks
|
|
26
|
+
input.buttonB.onEvent(ButtonEvent.Click, function() {
|
|
27
|
+
mouse.click(MouseButton.Right)
|
|
28
|
+
})
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## See also #seealso
|
|
32
|
+
|
|
33
|
+
[set button](/reference/mouse/set-button),
|
|
34
|
+
[turn wheel](/reference/mouse/turn-wheel)
|
|
35
|
+
|
|
36
|
+
```package
|
|
37
|
+
mouse
|
|
38
|
+
```
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# all Players
|
|
2
|
+
|
|
3
|
+
Get all players in the multiplayer game list.
|
|
4
|
+
|
|
5
|
+
```sig
|
|
6
|
+
mp.allPlayers()
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
If you want to access the player list for all of the players in the game, you can get the entire list of players in an array.
|
|
10
|
+
|
|
11
|
+
## Returns
|
|
12
|
+
|
|
13
|
+
* a [Player](/types/player) list for all of the players in the multiplayer game.
|
|
14
|
+
|
|
15
|
+
## Example #example
|
|
16
|
+
|
|
17
|
+
Find all the players that have a score greater than `20` and give them a bonus of `5` points.
|
|
18
|
+
|
|
19
|
+
```blocks
|
|
20
|
+
for (let player of mp.allPlayers()) {
|
|
21
|
+
if (mp.getPlayerState(player, MultiplayerState.score) > 20) {
|
|
22
|
+
mp.changePlayerStateBy(player, MultiplayerState.score, 5)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## See also #seealso
|
|
28
|
+
|
|
29
|
+
[player selector](/reference/multiplayer/player-selector),
|
|
30
|
+
[get player by number](/reference/multiplayer/get-player-by-number)
|
|
31
|
+
|
|
32
|
+
```package
|
|
33
|
+
multiplayer
|
|
34
|
+
```
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# is Connected
|
|
2
|
+
|
|
3
|
+
Check a player's connected state in the game.
|
|
4
|
+
|
|
5
|
+
```sig
|
|
6
|
+
mp.isConnected(mp.playerSelector(mp.PlayerNumber.One))
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Parameters
|
|
10
|
+
|
|
11
|
+
* **player**: the player to check the connected state for.
|
|
12
|
+
|
|
13
|
+
## Returns
|
|
14
|
+
|
|
15
|
+
* a [boolean](/types/boolean) value for the state of the connected state of the player, `true` for connected and `false` for disconnected.
|
|
16
|
+
|
|
17
|
+
## Example #example
|
|
18
|
+
|
|
19
|
+
If `player 2` is no longer connected to the game, let `player 1` win by default.
|
|
20
|
+
|
|
21
|
+
```blocks
|
|
22
|
+
let pressCount = 0
|
|
23
|
+
game.onUpdateInterval(10000, function () {
|
|
24
|
+
if (mp.isConnected(mp.playerSelector(mp.PlayerNumber.Two))) {
|
|
25
|
+
mp.gameOverPlayerWin(mp.playerSelector(mp.PlayerNumber.One))
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## See also #seealso
|
|
31
|
+
|
|
32
|
+
[get player state](/reference/multiplayer/get-player-state)
|
|
33
|
+
|
|
34
|
+
```package
|
|
35
|
+
multiplayer
|
|
36
|
+
```
|
|
@@ -471,7 +471,7 @@ namespace mp {
|
|
|
471
471
|
//% group=Player
|
|
472
472
|
//% weight=90
|
|
473
473
|
//% blockGap=8
|
|
474
|
-
//% help=multiplayer/
|
|
474
|
+
//% help=multiplayer/all-players
|
|
475
475
|
//% parts="multiplayer"
|
|
476
476
|
export function allPlayers(): Player[] {
|
|
477
477
|
return _mpstate().players.slice();
|
|
@@ -7,9 +7,14 @@ music.playTone(Note.C, 10)
|
|
|
7
7
|
```
|
|
8
8
|
|
|
9
9
|
## #simnote
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
|
|
11
|
+
### ~hint
|
|
12
|
+
|
|
13
|
+
#### Simulator
|
|
14
|
+
|
|
15
|
+
``||music:play tone||`` works on the @boardname@. It might not work in the simulator on every browser.
|
|
16
|
+
|
|
17
|
+
### ~
|
|
13
18
|
|
|
14
19
|
## Parameters
|
|
15
20
|
|
|
@@ -7,9 +7,14 @@ music.setTone(null)
|
|
|
7
7
|
```
|
|
8
8
|
|
|
9
9
|
## #simnote
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
|
|
11
|
+
### ~hint
|
|
12
|
+
|
|
13
|
+
#### Simulator
|
|
14
|
+
|
|
15
|
+
``||music:set tone||`` works on the @boardname@. It might not work in the simulator on every browser.
|
|
16
|
+
|
|
17
|
+
### ~
|
|
13
18
|
|
|
14
19
|
## Parameters
|
|
15
20
|
|
|
@@ -18043,7 +18043,7 @@ switch (step) {
|
|
|
18043
18043
|
return leave(s, r0)
|
|
18044
18044
|
default: oops()
|
|
18045
18045
|
} } }
|
|
18046
|
-
power_checkDeepSleep__P115330.info = {"start":
|
|
18046
|
+
power_checkDeepSleep__P115330.info = {"start":1084,"length":298,"line":36,"column":4,"endLine":46,"endColumn":5,"fileName":"pxt_modules/power/power.ts","functionName":"checkDeepSleep","argumentNames":[]}
|
|
18047
18047
|
|
|
18048
18048
|
function power_checkDeepSleep__P115330_mk(s) {
|
|
18049
18049
|
checkStack(s.depth);
|
|
@@ -18106,7 +18106,7 @@ switch (step) {
|
|
|
18106
18106
|
return leave(s, r0)
|
|
18107
18107
|
default: oops()
|
|
18108
18108
|
} } }
|
|
18109
|
-
power_init__P115332.info = {"start":
|
|
18109
|
+
power_init__P115332.info = {"start":1606,"length":376,"line":57,"column":4,"endLine":66,"endColumn":5,"fileName":"pxt_modules/power/power.ts","functionName":"init","argumentNames":[]}
|
|
18110
18110
|
|
|
18111
18111
|
function power_init__P115332_mk(s) {
|
|
18112
18112
|
checkStack(s.depth);
|
|
@@ -22178,7 +22178,7 @@ switch (step) {
|
|
|
22178
22178
|
return leave(s, r0)
|
|
22179
22179
|
default: oops()
|
|
22180
22180
|
} } }
|
|
22181
|
-
power_poke__P115329.info = {"start":
|
|
22181
|
+
power_poke__P115329.info = {"start":793,"length":81,"line":26,"column":4,"endLine":29,"endColumn":5,"fileName":"pxt_modules/power/power.ts","functionName":"poke","argumentNames":[]}
|
|
22182
22182
|
|
|
22183
22183
|
function power_poke__P115329_mk(s) {
|
|
22184
22184
|
checkStack(s.depth);
|
|
@@ -7524,7 +7524,7 @@ switch (step) {
|
|
|
7524
7524
|
return leave(s, r0)
|
|
7525
7525
|
default: oops()
|
|
7526
7526
|
} } }
|
|
7527
|
-
power_checkDeepSleep__P177795.info = {"start":
|
|
7527
|
+
power_checkDeepSleep__P177795.info = {"start":1084,"length":298,"line":36,"column":4,"endLine":46,"endColumn":5,"fileName":"pxt_modules/power/power.ts","functionName":"checkDeepSleep","argumentNames":[]}
|
|
7528
7528
|
|
|
7529
7529
|
function power_checkDeepSleep__P177795_mk(s) {
|
|
7530
7530
|
checkStack(s.depth);
|
|
@@ -7587,7 +7587,7 @@ switch (step) {
|
|
|
7587
7587
|
return leave(s, r0)
|
|
7588
7588
|
default: oops()
|
|
7589
7589
|
} } }
|
|
7590
|
-
power_init__P177797.info = {"start":
|
|
7590
|
+
power_init__P177797.info = {"start":1606,"length":376,"line":57,"column":4,"endLine":66,"endColumn":5,"fileName":"pxt_modules/power/power.ts","functionName":"init","argumentNames":[]}
|
|
7591
7591
|
|
|
7592
7592
|
function power_init__P177797_mk(s) {
|
|
7593
7593
|
checkStack(s.depth);
|
|
@@ -11999,7 +11999,7 @@ switch (step) {
|
|
|
11999
11999
|
return leave(s, r0)
|
|
12000
12000
|
default: oops()
|
|
12001
12001
|
} } }
|
|
12002
|
-
power_poke__P177794.info = {"start":
|
|
12002
|
+
power_poke__P177794.info = {"start":793,"length":81,"line":26,"column":4,"endLine":29,"endColumn":5,"fileName":"pxt_modules/power/power.ts","functionName":"poke","argumentNames":[]}
|
|
12003
12003
|
|
|
12004
12004
|
function power_poke__P177794_mk(s) {
|
|
12005
12005
|
checkStack(s.depth);
|
package/libs/power/power.ts
CHANGED
|
@@ -13,7 +13,7 @@ namespace power {
|
|
|
13
13
|
*/
|
|
14
14
|
//% blockId=powersetdeepsleeptimout block="power set deep sleep timeout to %seconds s"
|
|
15
15
|
//% seconds.defl=60
|
|
16
|
-
//% help
|
|
16
|
+
//% help=power/set-deep-sleep-timeout
|
|
17
17
|
export function setDeepSleepTimeout(seconds: number) {
|
|
18
18
|
init();
|
|
19
19
|
_timeout = seconds * 1000;
|
|
@@ -23,7 +23,7 @@ namespace power {
|
|
|
23
23
|
* Poke the activity watcher to keep the device awake.
|
|
24
24
|
*/
|
|
25
25
|
//% blockId=powerpke block="power poke"
|
|
26
|
-
//% help
|
|
26
|
+
//% help=power/poke
|
|
27
27
|
export function poke() {
|
|
28
28
|
init();
|
|
29
29
|
_poked = control.millis();
|
|
@@ -33,7 +33,7 @@ namespace power {
|
|
|
33
33
|
* Check if the device has had any "pokes" and needs to go into deep sleep mode.
|
|
34
34
|
*/
|
|
35
35
|
//% blockId=powercheckdeepsleep block="power check deep sleep"
|
|
36
|
-
//% help
|
|
36
|
+
//% help=power/check-deep-sleep
|
|
37
37
|
export function checkDeepSleep() {
|
|
38
38
|
init();
|
|
39
39
|
const p = _poked || 0;
|
|
@@ -51,7 +51,7 @@ namespace power {
|
|
|
51
51
|
*/
|
|
52
52
|
//% blockId=powerdeepsleep block="power deep sleep"
|
|
53
53
|
//% shim=pxt::deepSleep
|
|
54
|
-
//% help
|
|
54
|
+
//% help=power/deep-sleep
|
|
55
55
|
export function deepSleep() {
|
|
56
56
|
}
|
|
57
57
|
|