restructuring to separate language from API

This commit is contained in:
Tom Ball
2016-06-14 17:20:45 -04:00
parent beac252620
commit a0a23a261c
40 changed files with 141 additions and 164 deletions

View File

@ -65,5 +65,5 @@ input.onButtonPressed(Button.A, () => {
### See also
[while](/reference/loops/while), [on button pressed](/reference/input/on-button-pressed), [in background](/reference/control/in-background)
[while](/blocks/loops/while), [on button pressed](/reference/input/on-button-pressed), [in background](/reference/control/in-background)

View File

@ -26,5 +26,5 @@ for (let i = 0; i < 5; i++) {
### See also
[while](/reference/loops/while), [running time](/reference/input/running-time), [for](/reference/loops/for)
[while](/blocks/loops/while), [running time](/reference/input/running-time), [for](/blocks/loops/for)

View File

@ -28,7 +28,7 @@ basic.showNumber(x)
### Example: count to 5
This example uses a [for](/reference/loops/for) loop to show numbers ``0`` through ``5`` on the screen:
This example uses a [for](/blocks/loops/for) loop to show numbers ``0`` through ``5`` on the screen:
~~~~blocks
for (let i = 0; i < 6; i++) {
@ -44,5 +44,5 @@ for (let i = 0; i < 6; i++) {
### See also
[show string](/reference/basic/show-string), [show animation](/reference/basic/show-animation), [Number](/reference/types/number), [math library](/reference/math)
[show string](/reference/basic/show-string), [show animation](/reference/basic/show-animation), [Number](/reference/types/number), [math](/blocks/math)

View File

@ -51,5 +51,5 @@ input.onButtonPressed(Button.A, () => {
### See also
[while](/reference/loops/while), [forever](/reference/basic/forever), [on button pressed](/reference/input/on-button-pressed)
[while](/blocks/loops/while), [forever](/reference/basic/forever), [on button pressed](/reference/input/on-button-pressed)

View File

@ -11,7 +11,7 @@ input.onButtonPressed(Button.A, () => {
game.startCountdown(10000)
```
### [Create sprite](/functions/game-library/create-sprite)
### [Create sprite](/reference/game/create-sprite)
Create sprite with x, y coordinates and returns a LED Sprite. Create a new LED sprite.
@ -21,7 +21,7 @@ Create sprite with x, y coordinates and returns a LED Sprite. Create a new LED s
export function createSprite(x: number, y: number) : micro_bitSprites.LedSprite
```
### [Move](/functions/game-library/move)
### [Move](/reference/game/move)
Sprite move by a certain number
@ -31,7 +31,7 @@ Sprite move by a certain number
export function move(_this: micro_bitSprites.LedSprite, leds: number)
```
### [Turn](/functions/game-library/turn)
### [Turn](/reference/game/turn)
Rotates a sprite to the right by a certain number of degrees
@ -47,7 +47,7 @@ Rotates a sprite to the left by a certain number of degrees
export function turnLeft(_this: micro_bitSprites.LedSprite, degrees: number)
```
### [Change](/functions/game-library/change)
### [Change](/reference/game/change)
Sprite will change the x position by this number
@ -63,7 +63,7 @@ Sprite will change the y position by this number
export function changeYBy(_this: micro_bitSprites.LedSprite, y: number)
```
### [Set](/functions/game-library/set)
### [Set](/reference/game/set)
Sprite will change the x position by this number
@ -79,7 +79,7 @@ Sprite will change the y position by this number
export function changeYBy(_this: micro_bitSprites.LedSprite, y: number)
```
### [If on edge, bounce](/functions/game-library/if-on-edge-bounce)
### [If on edge, bounce](/reference/game/if-on-edge-bounce)
Sprite - If the sprite is on the edge, the sprite will bounce
@ -89,7 +89,7 @@ Sprite - If the sprite is on the edge, the sprite will bounce
export function ifOnEdge_Bounce(_this: micro_bitSprites.LedSprite)
```
### [Change score by](/functions/game-library/change-score-by)
### [Change score by](/reference/game/change-score-by)
When a player achieves a goal, you can increase the game score
@ -101,7 +101,7 @@ When a player achieves a goal, you can increase the game score
export function addScore(points: number)
```
### [Score](/functions/game-library/score)
### [Score](/reference/game/score)
* set the current score to a particular value.
@ -117,7 +117,7 @@ export function setScore(value: number)
export function score() : number
```
### [Countdown](/functions/game-library/start-countdown)
### [Countdown](/reference/game/start-countdown)
If your game has a time limit, you can start a countdown in which case `game->current time` returns the remaining time.
@ -129,7 +129,7 @@ If your game has a time limit, you can start a countdown in which case `game->cu
export function startCountdown(ms: number)
```
### [Game over](/functions/game-library/game-over)
### [Game over](/reference/game/game-over)
If the `life` reaches zero or the time expires (see countdown), the game enters the **game over** mode. When the game is over, `game->is running` returns false

View File

@ -8,7 +8,7 @@ An *Image* is a matrix of pixels to show on the [LED screen](/device/screen)
### Block Editor: Show LEDs
To display an image using the [Block Editor](/blocks/editor):
To display an image:
* click `Basic` , `Show LEDs`, and tap on the LEDs`
* when you're done, return to your code
@ -21,10 +21,6 @@ You should see code similar to this:
To create an image that you can later modify, see the [create image](/reference/images/create-image) function.
### Block editor: create and show images
To create images using the [Block editor](/blocks/editor):
1. Click the **Images** category on the left.
2. Drag and drop the **show image** block into your code.

View File

@ -29,7 +29,7 @@ img.showImage(0)
### Example: display numbers 1-5
The following example creates an image with 5 frames and then uses a [for loop](/reference/loops/for) to show each frame on the screen:
The following example creates an image with 5 frames and then uses a [for loop](/blocks/loops/for) to show each frame on the screen:
```
let img2 = images.createImage(`

View File

@ -38,7 +38,7 @@ let w = img.width()
### Example: show each frame
The following example uses the `width` function with a [for](/reference/loops/for) loop to show each image frame on the screen:
The following example uses the `width` function with a [for](/blocks/loops/for) loop to show each image frame on the screen:
```
let img2 = images.createImage(`

View File

@ -16,7 +16,7 @@ input.buttonIsPressed(Button.A);
### Example
This program uses an [if](/reference/logic/if) to run
This program uses an [if](/blocks/logic/if) to run
one part of the program if the `A` button is pressed, and
another part if it is not pressed.
@ -35,5 +35,5 @@ basic.forever(() => {
### See also
[on button pressed](/reference/input/on-button-pressed), [if](/reference/logic/if), [forever](/reference/basic/forever)
[on button pressed](/reference/input/on-button-pressed), [if](/blocks/logic/if), [forever](/reference/basic/forever)

View File

@ -43,5 +43,5 @@ Otherwise, sometimes they would show a `0`.
### See also
[button is pressed](/reference/input/button-is-pressed), [forever](/reference/basic/forever), [random](/reference/math/math)
[button is pressed](/reference/input/button-is-pressed), [forever](/reference/basic/forever), [random](/blocks/math)

View File

@ -39,7 +39,7 @@ led.plot(4, 4)
### Example: Square
This program uses a [for loop](/reference/loops/for)
This program uses a [for loop](/blocks/loops/for)
and the `plot` function
to make a square around the edges of the LED screen.

View File

@ -1,9 +0,0 @@
# Logic
```cards
if(true) {}
true;
true && false;
!true;
1 != 0;
```

View File

@ -1,28 +0,0 @@
# If
### @parent blocks/language
Conditionally run code depending on whether a [Boolean](/reference/types/boolean) condition is true or false.
```blocks
if(true) {
}
```
In the Block Editor, click on the dark blue gear icon (see above) to add an *else* or *if* to the current block.
### Example: adjusting screen brightness
```blocks
if(input.lightLevel()<100){
led.setBrightness(255);
}
```
If the [light level](/input/light-level) is `< 100`, this code sets the brightness to `255`:
### See also
[while loop](/reference/loops/while), [for](/reference/loops/for), [boolean](/reference/types/boolean)

View File

@ -1,7 +0,0 @@
# Loops
```cards
for(let i = 0;i<5;i++) {}
while(true) {}
basic.forever(() => {})
```

View File

@ -1,20 +0,0 @@
# For
### @parent blocks/language
Run part of the program the number of times you say.
### Example: Count to 4
This program will show the numbers 0, 1, 2, 3, and 4 one after another on the LED screen.
```blocks
for(let i = 0; i < 5; ++i) {
basic.showNumber(i)
}
```
### See also
[repeat](/reference/loops/repeat), [while](/reference/loops/while), [if](/reference/logic/if), [show number](/reference/basic/show-number)

View File

@ -1,12 +0,0 @@
# Repeat
Run part of the program the number of times you say.
### Block Editor
![](/static/mb/blocks/contents-0.png)
### See also
[for](/reference/loops/for), [while](/reference/loops/while), [if](/reference/logic/if), [show number](/reference/basic/show-number)

View File

@ -1,32 +0,0 @@
# While
### @parent blocks/language
Repeat code while a [Boolean](/reference/types/boolean) `condition` is true.
```blocks
while(true) {
}
```
The while loop has a *condition* that evaluates to a [Boolean](/reference/types/boolean) value. After the `do` keyword, add the code that you want to run while the `condition` is `true`. The while loop concludes with `end while`.
The condition is tested before any code runs. Which means that if the condition is false, the code inside the loop doesn't execute.
### Example: diagonal line
The following example uses a while loop to make a diagonal line on the LED screen (points `0, 0`, `1, 1`, `2, 2`, `3, 3`, `4, 4`).
```blocks
let index = 4;
while(index >= 0) {
led.plot(index, index);
index--;
}
```
### See also
[on button pressed](/reference/input/on-button-pressed), [for](/reference/loops/for), [if](/reference/logic/if), [forever](/reference/basic/forever)

View File

@ -1,37 +0,0 @@
# Math
[Numeric](/reference/types/number) values: 0, 1, 2, ...
```blocks
0;
1;
2;
```
Arithmetic binary operation (+, -, *, /)
```blocks
0+1;
0-1;
1*2;
3/4;
```
Absolute value
```blocks
Math.abs(-5);
```
Minimum/maximum of two values
```blocks
Math.min(0, 1);
Math.max(0, 1);
```
Random value
```blocks
Math.random(5);
```

View File

@ -1,48 +0,0 @@
# Math Library
Functions in the math library.
### @parent blocks/language
The math library includes math related functions that you can use with [Numbers](/reference/types/number).
* In the [Block editor](/blocks/editor), click **maths** on the left to see the available blocks
The functions available in Block Editor are:
### abs
math `->` abs (x : [Number](/reference/types/number)) *returns* [Number](/reference/types/number)
returns the absolute value of input parameter `x`
![](/static/mb/blocks/math-0.png)
### max
math `->` max (x : [Number](/reference/types/number), y : [Number](/reference/types/number)) *returns* [Number](/reference/types/number)
returns the larger of two input numbers (`x` and `y`)
![](/static/mb/blocks/math-1.png)
### min
math `->` min (x : [Number](/reference/types/number), y : [Number](/reference/types/number)) *returns* [Number](/reference/types/number)
returns the smaller of two input numbers (`x` and `y`)
![](/static/mb/blocks/math-2.png)
### random
math `->` random (limit : [Number](/reference/types/number)) *returns* [Number](/reference/types/number)
returns a random [Number](/reference/types/number) between 0 and the parameter *limit*
![](/static/mb/blocks/math-3.png)
### See also
[Block Editor documentation](/blocks/contents), [Number](/reference/types/number)

View File

@ -1,17 +1,13 @@
# types
Touch Develop types.
### @parent language
A *type* refers to a class of data and the operations permitted on that data. The following types are supported by Block Editor for the BBC micro:bit:
A *type* refers to a class of data and the operations permitted on that class of data.
The following built-in types are supported for the BBC micro:bit:
* **[String](/reference/types/string)**: a sequence of characters
* **[Number](/reference/types/number)**: an integer number (32-bit signed)
* **[Boolean](/reference/types/boolean)**: true or false
* **[Image](/blocks/image)**: a collection of [micro:bit LED states](/device/screen) (on/off)
### see also
TypeScript allows you to create user-defined classes of data.
[local variables](/reference/variables/var), [assignment operator](/reference/variables/assign)

View File

@ -32,7 +32,7 @@ The next six blocks represent comparison operators that yield a Boolean value. M
42 >= 0;
```
Boolean values and operators are often used with an [if](/reference/logic/if) or [while](/reference/loops/while) statement to determine which code will execute next. For example:
Boolean values and operators are often used with an [if](/blocks/logic/if) or [while](/blocks/loops/while) statement to determine which code will execute next. For example:
### Functions that return a Boolean
@ -100,5 +100,5 @@ See the documentation on [Numbers](/reference/types/number) for more information
### See also
[if](/reference/logic/if), [while](/reference/loops/while), [number](/reference/types/number)
[if](/blocks/logic/if), [while](/blocks/loops/while), [number](/reference/types/number)

View File

@ -6,13 +6,13 @@ a piece of text.
A *String* is a sequence of characters. For the BBC micro:bit, ASCII character codes 32 to 126 are supported; letters, digits, punctuation marks, and a few symbols. All other character codes appear as a ? on the [LED screen](/device/screen).
### Declare a string
### Create a string variable
Use the [var statement](/reference/variables/var) and the [assignment operator](/reference/variables/assign) to declare a new *local* string variable. Like this:
```block
salutation = "Hello";
```
![](/static/mb/blocks/string-0.png)
To declare a string using the [Block Editor](/blocks/editor):
To create a variable that holds a string:
1. Click `Variables` (as the Block drawer).
@ -24,17 +24,22 @@ To declare a string using the [Block Editor](/blocks/editor):
Your code should look something like this:
![](/static/mb/blocks/string-1.png)
```block
salutation = "Hello";
```
### The function `show string`
Use [show string](/reference/basic/show-string) to display a string on the [LED screen](/device/screen). If the string is multiple characters, the string scrolls right to left. The following example displays `Hello world!` on the micro:bit screen:
Use [show string](/reference/basic/show-string) to display a string on the [LED screen](/device/screen).
If the string is multiple characters, the string scrolls right to left. The following example displays `Hello world!` on the micro:bit screen:
![](/static/mb/blocks/string-2.png)
```block
basic.showString("Hello world!");
```
The parameter of `show string` specifies the string
### See also
[variables](/reference/variables/var), [string functions](/reference/types/string-functions), [Number](/reference/types/number), [show string](/reference/basic/show-string)
[string functions](/reference/types/string-functions), [Number](/reference/types/number), [show string](/reference/basic/show-string)

View File

@ -1,21 +0,0 @@
## Variables
[Assign](/reference/variables/assign) (set) a variable's value
```blocks
let x = 0;
```
Get a variable's value
```blocks
let x = 0;
x;
```
[Change](/reference/variables/change-var) a variable's value
```blocks
let x = 0;
x+=1;
```

View File

@ -1,36 +0,0 @@
# Assignment Operator
Use an equals sign to make a [variable](/reference/variables/var) store the [number](/reference/types/number)
or [string](/reference/types/string) you say.
When you use the equals sign to store something in a variable, the equals sign is called
an *assignment operator*, and what you store is called a *value*.
### Storing numbers in variables
This program makes the variable `item` equal `5` and then shows it on the [LED screen](/device/screen).
````blocks
let item = 5
basic.showNumber(item)
````
### Storing strings in variables
This program makes the variable `name` equal `Joe` and then shows it on the [LED screen](/device/screen).
````blocks
let name = "Joe"
basic.showString(name);
````
### Notes
You can use the assignment operator with variables of
every [type](/reference/types). A *type* is which kind of thing
a variable can store, like a number or string.
### See also
[variable](/reference/variables/var), [types](/reference/types)

View File

@ -1,40 +0,0 @@
# Change Value
Set the value for local and global variables.
### @parent blocks/change-value
Change the value of a variable
```blocks
let x = 0
x += 1
```
### Declare a variable
Use the assignment operator to set the value of a [variable](/reference/variables/var). Change the value of a variable from 0 to 1 using the change item block. Like this:
```blocks
let x = 0
x += 1
```
### Example
Use the assignment operator to set the value of a [variable](/reference/variables/var). Change the value of a variable from 0 to 1 using the change item block. Then display the new value of the variable on the LED screen. Like this:
```blocks
let x = 0;
x += 1;
basic.showNumber(x);
```
### Notes
* You can use the assignment operator with variables of each of the supported [types](/reference/types).
### See also
[variable](/reference/variables/var), [types](/reference/types)

View File

@ -1,87 +0,0 @@
# Local Variables
How to define and use local variables.
### @parent language
A variable is a place where you can store and retrieve data. Variables have a name, a [type](/reference/types), and value:
* *name* is how you'll refer to the variable
* *type* refers to the kind of data a variable can store
* *value* refers to what's stored in the variable
### Var statement
Use the Block Editor variable statement to create a variable
and the [assignment operator](/reference/variables/assign)
to store something in the variable.
For example, this code stores the number `2` in the `x` variable:
```blocks
let x = 2;
```
Here's how to define a variable in the Block Editor:
1. Click `variables`.
2. Change the default variable name if you like.
3. Drag a block type on the right-side of the [assignment operator](/reference/variables/assign) and click the down arrow to change the variable name.
A variable is created for the number returned by the [brightness](/reference/led/brightness) function.
```blocks
let b = led.brightness();
```
### Using variables
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:
```blocks
let counter = 1;
basic.showNumber(counter);
```
To change the contents of a variable use the assignment operator. The following code sets `counter` to 1 and then increments `counter` by 10:
```blocks
let counter = 1;
counter = counter + 10;
basic.showNumber(counter);
```
### Why use variables?
If you want to remember and modify data, you'll need a variable.
A counter is a great example:
```blocks
let counter = 0;
input.onButtonPressed(Button.A, () => {
counter = counter + 1;
basic.showNumber(counter);
});
```
### Local variables
Local variables exist only within the function or block of code where they're defined. For example:
```blocks
// x does NOT exist here.
if (led.brightness() > 128) {
// x exists here
let x = 0;
}
```
#### Notes
* You can use the default variable names if you'd 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 "new variable".
### See also
[types](/reference/types), [assignment operator](/reference/variables/assign)