pxt-microbit 7.1.14 → 7.1.16
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/block-tests.js +1 -1
- package/built/target.js +1 -1
- package/built/target.json +1 -1
- package/built/targetlight.json +1 -1
- package/built/web/rtlsemantic.css +1 -1
- package/built/web/semantic.css +1 -1
- package/docs/blocks/variables/assign.md +26 -3
- package/docs/blocks/variables/var.md +75 -31
- package/docs/extensions/extension-gallery.md +4 -0
- package/docs/types/string.md +22 -4
- package/package.json +2 -2
- package/pxtarget.json +0 -6
- package/targetconfig.json +8 -1
|
@@ -1,11 +1,34 @@
|
|
|
1
1
|
# Assignment Operator
|
|
2
2
|
|
|
3
|
-
Use an equals sign to make a [variable](/blocks/variables/var) store
|
|
4
|
-
or [string](/types/string) you say.
|
|
3
|
+
Use an equals sign to make a [variable](/blocks/variables/var) store a [number](/types/number), [string](/types/string), or other [type](/types) of value.
|
|
5
4
|
|
|
6
|
-
When you use the equals sign to store something in a variable, the equals sign is called
|
|
5
|
+
When you use the equals sign (**=**) to store something in a variable, the equals sign is called
|
|
7
6
|
an *assignment operator*, and what you store is called a *value*.
|
|
8
7
|
|
|
8
|
+
When you work in JavaScript or Python the equals sign is used:
|
|
9
|
+
|
|
10
|
+
```typescript-ignore
|
|
11
|
+
item = 3
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## The 'set' block
|
|
15
|
+
|
|
16
|
+
In blocks, a variable assignment happens with the ``||variables:set||`` block when you set a value to a [variable](/blocks/variables/var).
|
|
17
|
+
|
|
18
|
+
```block
|
|
19
|
+
let item = 3
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### ~ hint
|
|
23
|
+
|
|
24
|
+
#### Setting a variable using the Toolbox
|
|
25
|
+
|
|
26
|
+
In the ``||variables:Variables||`` category of the **Toolbox** you can create or choose a variable to assign:
|
|
27
|
+
|
|
28
|
+

|
|
29
|
+
|
|
30
|
+
### ~
|
|
31
|
+
|
|
9
32
|
## Storing numbers in variables
|
|
10
33
|
|
|
11
34
|
This program makes the variable `item` equal `5` and then shows it on the [LED screen](/device/screen).
|
|
@@ -1,38 +1,60 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Declaring variables
|
|
2
2
|
|
|
3
|
-
How to
|
|
3
|
+
How to declare and use variables.
|
|
4
4
|
|
|
5
5
|
## @parent language
|
|
6
6
|
|
|
7
|
-
A variable is a place where you can store and retrieve data. Variables have a name, a [type](/types), and value:
|
|
7
|
+
A variable is a place where you can store and retrieve data. Variables have a name, a [type](/types), and a value:
|
|
8
8
|
|
|
9
9
|
* *name* is how you'll refer to the variable
|
|
10
|
-
* *type*
|
|
11
|
-
* *value*
|
|
10
|
+
* *type* is the kind of data a variable can store
|
|
11
|
+
* *value* is what's stored in the variable
|
|
12
12
|
|
|
13
|
-
##
|
|
13
|
+
## The variable (var) statement
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
and the [assignment operator](/blocks/variables/assign)
|
|
17
|
-
to store something in the variable.
|
|
15
|
+
A variable is created using a `variable` statement. The variable will "declare" itself in this statement. In MakeCode JavaScript a variable is declared along with its first [assignment](/blocks/variables/assign):
|
|
18
16
|
|
|
19
|
-
|
|
17
|
+
```typescript
|
|
18
|
+
let x = 2
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
With Python a variable is declared when it's first used. In this case the variable statement is just the assignment of the variable:
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
x = 2
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
If a variable is declared in blocks you will see the ``||variables:set||`` block with the first use of the variable. This code stores the number `2` in the `x` variable:
|
|
20
28
|
|
|
21
29
|
```blocks
|
|
22
|
-
let x = 2
|
|
30
|
+
let x = 2
|
|
23
31
|
```
|
|
24
|
-
Here's how to define a variable in the Block Editor:
|
|
25
32
|
|
|
26
|
-
|
|
33
|
+
The new variable is created inside the ``||variables:Variables||`` category of the **Toolbox**.
|
|
34
|
+
|
|
35
|
+
### ~ hint
|
|
27
36
|
|
|
28
|
-
|
|
37
|
+
#### Creating a variable from the Toolbox
|
|
29
38
|
|
|
30
|
-
|
|
39
|
+
In the ``||variables:Variables||`` category of the **Toolbox** you can create new variable:
|
|
40
|
+
|
|
41
|
+

|
|
42
|
+
|
|
43
|
+
Here's how to create a variable using the Toolbox:
|
|
44
|
+
|
|
45
|
+
1. Click ``||variables:Variables||`` in the Toolbox.
|
|
46
|
+
2. Click on **Make a Variable...**.
|
|
47
|
+
3. Choose a name for your variable, type it in, and click **Ok**.
|
|
48
|
+
4. Drag the new variable, ``||variables:set||`` or ``||variables:change||`` block into your code.
|
|
49
|
+
|
|
50
|
+
### ~
|
|
51
|
+
|
|
52
|
+
### Quick example
|
|
31
53
|
|
|
32
54
|
A variable is created for the number returned by the [brightness](/reference/led/brightness) function.
|
|
33
55
|
|
|
34
56
|
```blocks
|
|
35
|
-
let b = led.brightness()
|
|
57
|
+
let b = led.brightness()
|
|
36
58
|
```
|
|
37
59
|
|
|
38
60
|
## Using variables
|
|
@@ -40,16 +62,16 @@ let b = led.brightness();
|
|
|
40
62
|
Once you've defined a variable, just use the variable's name whenever you need what's stored in the variable. For example, the following code shows the value stored in `counter` on the LED screen:
|
|
41
63
|
|
|
42
64
|
```blocks
|
|
43
|
-
let counter = 1
|
|
44
|
-
basic.showNumber(counter)
|
|
65
|
+
let counter = 1
|
|
66
|
+
basic.showNumber(counter)
|
|
45
67
|
```
|
|
46
68
|
|
|
47
69
|
To change the contents of a variable use the assignment operator. The following code sets `counter` to 1 and then increments `counter` by 10:
|
|
48
70
|
|
|
49
71
|
```blocks
|
|
50
|
-
let counter = 1
|
|
51
|
-
counter = counter + 10
|
|
52
|
-
basic.showNumber(counter)
|
|
72
|
+
let counter = 1
|
|
73
|
+
counter = counter + 10
|
|
74
|
+
basic.showNumber(counter)
|
|
53
75
|
```
|
|
54
76
|
|
|
55
77
|
## Why use variables?
|
|
@@ -58,11 +80,11 @@ If you want to remember and modify data, you'll need a variable.
|
|
|
58
80
|
A counter is a great example:
|
|
59
81
|
|
|
60
82
|
```blocks
|
|
61
|
-
let counter = 0
|
|
62
|
-
input.onButtonPressed(Button.A, ()
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
})
|
|
83
|
+
let counter = 0
|
|
84
|
+
input.onButtonPressed(Button.A, function () {
|
|
85
|
+
counter = counter + 1
|
|
86
|
+
basic.showNumber(counter)
|
|
87
|
+
})
|
|
66
88
|
```
|
|
67
89
|
|
|
68
90
|
## Local variables
|
|
@@ -72,16 +94,38 @@ Local variables exist only within the function or block of code where they're de
|
|
|
72
94
|
```blocks
|
|
73
95
|
// x does NOT exist here.
|
|
74
96
|
if (led.brightness() > 128) {
|
|
75
|
-
|
|
76
|
-
|
|
97
|
+
// x exists here
|
|
98
|
+
let x = 0
|
|
77
99
|
}
|
|
78
100
|
```
|
|
79
101
|
|
|
80
|
-
|
|
102
|
+
## Notes about variables
|
|
103
|
+
|
|
104
|
+
### Variable names
|
|
81
105
|
|
|
82
|
-
|
|
106
|
+
Some blocks come from the Toolbox with default variable names, such as `list` from ``||arrays:Arrays||``.
|
|
107
|
+
You can use the default variable names if you like, however, it's best to use descriptive variable names. To change a variable name in the editor, select the down arrow next to the variable and then click **"Rename variable..."** to change it.
|
|
108
|
+
|
|
109
|
+
### Hidden declaration block
|
|
110
|
+
|
|
111
|
+
If a variable is used more than once, and its declaration block sets the variable to `0`, that first declaration block is hidden. For example:
|
|
112
|
+
|
|
113
|
+
```blocks
|
|
114
|
+
let x = 0
|
|
115
|
+
if (x == 0) {
|
|
116
|
+
x = 9
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
You don't see any first block setting the variable `x` to `0` but that happens in its hidden declaration statement. You'll see the declaration statement, `let x = 0`, if you switch from Blocks to JavaScript in the Editor:
|
|
121
|
+
|
|
122
|
+
```typescript-ignore
|
|
123
|
+
let x = 0
|
|
124
|
+
if (x == 0) {
|
|
125
|
+
x = 9
|
|
126
|
+
}
|
|
127
|
+
```
|
|
83
128
|
|
|
84
129
|
## See also
|
|
85
130
|
|
|
86
131
|
[types](/types), [assignment operator](/blocks/variables/assign)
|
|
87
|
-
|
|
@@ -521,6 +521,10 @@ Many extensions are available to work with interface kits, add-on hardware, or o
|
|
|
521
521
|
|
|
522
522
|
```codecard
|
|
523
523
|
[{
|
|
524
|
+
"name": "Kitronik Craft & Code",
|
|
525
|
+
"url":"/pkg/KitronikLtd/pxt-kitronik-Craft-and-Code",
|
|
526
|
+
"cardType": "package"
|
|
527
|
+
}, {
|
|
524
528
|
"name": "Lectrify Brick:Bit",
|
|
525
529
|
"url":"/pkg/softsmyth/lectrify-b4k",
|
|
526
530
|
"cardType": "package"
|
package/docs/types/string.md
CHANGED
|
@@ -1,9 +1,27 @@
|
|
|
1
1
|
# @extends
|
|
2
2
|
|
|
3
|
-
## #
|
|
3
|
+
## #create
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
In the ``||variables:Variables||`` category of the **Toolbox** you can create new variable:
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+

|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Here's how to create a string variable using the Toolbox:
|
|
10
|
+
|
|
11
|
+
1. Click ``||variables:Variables||`` in the Toolbox.
|
|
12
|
+
2. Click on **Make a Variable...**.
|
|
13
|
+
3. Choose a name for your variable, type it in, and click **Ok**.
|
|
14
|
+
4. Drag the new ``||variables:set||`` block into your code.
|
|
15
|
+
5. Click on the ``||text:Text||`` drawer in the Toolbox and find the ``||text:" "||`` block.
|
|
16
|
+
6. Drag the ``||text:" "||`` block into the value slot in of your variable ``||variables:set||`` block.
|
|
17
|
+
|
|
18
|
+
## Characters you use in strings #custom
|
|
19
|
+
|
|
20
|
+
### ~ hint
|
|
21
|
+
|
|
22
|
+
#### Character sets
|
|
23
|
+
|
|
24
|
+
The available characters to use for a language is called the _character set_. Each character in the set has a number code to match it with.
|
|
25
|
+
To display characters on the [LED screen](/device/screen), the @boardname@, uses the "ASCII" character codes of `32` to `126`; letters, digits, punctuation marks, and a few symbols. All other character codes appear as a `?` on the LED screen.
|
|
26
|
+
|
|
27
|
+
### ~
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pxt-microbit",
|
|
3
|
-
"version": "7.1.
|
|
3
|
+
"version": "7.1.16",
|
|
4
4
|
"description": "micro:bit target for Microsoft MakeCode (PXT)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"JavaScript",
|
|
@@ -46,6 +46,6 @@
|
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"pxt-common-packages": "12.1.4",
|
|
49
|
-
"pxt-core": "11.
|
|
49
|
+
"pxt-core": "11.3.5"
|
|
50
50
|
}
|
|
51
51
|
}
|
package/pxtarget.json
CHANGED
|
@@ -261,12 +261,6 @@
|
|
|
261
261
|
"localHostUrl": "http://localhost:3000/microbit-robot/?parentOrigin=$PARENT_ORIGIN$",
|
|
262
262
|
"aspectRatio": 1.22,
|
|
263
263
|
"permanent": true
|
|
264
|
-
},
|
|
265
|
-
"arcadeshield": {
|
|
266
|
-
"url": "https://microsoft.github.io/pxt-arcadeshield/?parentOrigin=$PARENT_ORIGIN$",
|
|
267
|
-
"localHostUrl": "http://localhost:3000/?parentOrigin=$PARENT_ORIGIN$",
|
|
268
|
-
"aspectRatio": 1.22,
|
|
269
|
-
"permanent": true
|
|
270
264
|
}
|
|
271
265
|
},
|
|
272
266
|
"testSimulatorExtensions": {},
|
package/targetconfig.json
CHANGED
|
@@ -465,19 +465,26 @@
|
|
|
465
465
|
"pythom1234/pxt-oled": { "tags": [ "Lights and Display" ] },
|
|
466
466
|
"softsmyth/lectrify-b4k": { "tags": [ "Robotics" ] },
|
|
467
467
|
"davidnsousa/sonification": { "tags": [ "Software" ] },
|
|
468
|
+
"shahart/heb-microbit": { "tags": [ "Software" ] },
|
|
469
|
+
"kitronikltd/pxt-kitronik-craft-and-code": { "tags": [ "Robotics" ] },
|
|
468
470
|
"microsoft/pxt-simx-sample": {
|
|
469
471
|
"simx": {
|
|
470
472
|
"sha": "7301f5900879b85127482d79bab48f03c25690a8",
|
|
471
473
|
"devUrl": "http://localhost:5173"
|
|
472
474
|
}
|
|
473
475
|
},
|
|
474
|
-
"shahart/heb-microbit": { "tags": [ "Software" ] },
|
|
475
476
|
"microbit-foundation/pxt-microbit-ml": {
|
|
476
477
|
"simx": {
|
|
477
478
|
"sha": "e349a2feaae9f84a24ebd56716209ef74e1758d2",
|
|
478
479
|
"devUrl": "http://localhost:5173",
|
|
479
480
|
"aspectRatio": 3.45
|
|
480
481
|
}
|
|
482
|
+
},
|
|
483
|
+
"microbit-apps/pxt-arcadeshield": {
|
|
484
|
+
"simx": {
|
|
485
|
+
"sha": "5bac5ff5b80621b53b746e4bbe252e406b992bdb",
|
|
486
|
+
"devUrl": "http://localhost:3000"
|
|
487
|
+
}
|
|
481
488
|
}
|
|
482
489
|
},
|
|
483
490
|
"approvedEditorExtensionUrls": [
|