# Reporter blocks and Statement blocks

**URL:** https://forum.makecode.com/t/reporter-blocks-and-statement-blocks/11133
**Category:** PXT
**Created:** [November 29, 2021, 5:19pm UTC](https://forum.makecode.com/t/reporter-blocks-and-statement-blocks/11133 "2021-11-29T17:19:23Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![THEb0nny](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/theb0nny/32/3500_2.png) [@THEb0nny](https://forum.makecode.com/u/THEb0nny)
#### Post date: [November 29, 2021, 5:19pm UTC](https://forum.makecode.com/t/reporter-blocks-and-statement-blocks/11133/1 "2021-11-29T17:19:23Z")

</div>

Privet, ya khochu poprobovat’ sozdat’ blok operatora ?: YA smotryu dokumentatsiyu [https://makecode.com/defining-blocks](https://makecode.com/defining-blocks) no ya ne ponimayu kak rabotayet primer koda. YA skopiroval i vstavil v custom.ts: /\*\* \* Custom blocks _/ namespace logic { /_\* \* Remove the last element from an array and return it. _/ //% blockId=“array\_pop” block=“get and remove last value from %list” function pop(): number; /_\* \* Remove the last element from an array and return it. \*/ //% blockId=“array\_pop\_statement” block=“remove last value from %list” //% blockAliasFor=“Array.pop” function \_popStatement(): void; } no u menya oshibka na pop i na \_popStatement. Mozhete pokazat’ boleye ponyatnyy primer?  
Ещё  
714 / 5000  
Результаты перевода  
Hi, I want to try creating a statement block?:  
I am looking at the documentation [https://makecode.com/defining-blocks](https://makecode.com/defining-blocks)  
but I don’t understand how the sample code works.  
I copied and pasted to custom.ts:  
/ \*\*

- Custom blocks

- /  
namespace logic {  
/ \*\*

but i got error on pop and on \_popStatement.

Can you provide a clearer example?

---

<div class="post-metadata">

### Author: ![THEb0nny](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/theb0nny/32/3500_2.png) [@THEb0nny](https://forum.makecode.com/u/THEb0nny)
#### Post date: [November 30, 2021, 5:49pm UTC](https://forum.makecode.com/t/reporter-blocks-and-statement-blocks/11133/2 "2021-11-30T17:49:36Z")

</div>

This does not seem to be the same example as I thought.  
I tried making a block with ternary conditional. I suggest adding such a block to the cloud so that it is convenient not to pile up blocks.

 ![Screenshot_1](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/4/46d25660699720b07e1640e98f7d6e9315f43822.jpeg)

```auto
//% blockId=ternary_conditional
    //% block="if $condition| then $expression1| else $expression2"
    export function ternaryConditional(condition: boolean, expression1: any, expression2: any): any {
        return (condition? expression1 : expression2);
    }

```

---

<div class="post-metadata">

### Author: ![THEb0nny](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/theb0nny/32/3500_2.png) [@THEb0nny](https://forum.makecode.com/u/THEb0nny)
#### Post date: [November 30, 2021, 10:05pm UTC](https://forum.makecode.com/t/reporter-blocks-and-statement-blocks/11133/3 "2021-11-30T22:05:17Z")

</div>

In which files can you find building blocks to try changing them?

---

<div class="post-metadata">

### Author: ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)
#### Post date: [November 30, 2021, 10:11pm UTC](https://forum.makecode.com/t/reporter-blocks-and-statement-blocks/11133/4 "2021-11-30T22:11:52Z")

</div>

@THEb0nny what blocks specifically are you trying to find? Most blocks for arcade are in [pxt-common-packages](https://github.com/microsoft/pxt-common-packages) in this folder:

> **[pxt-common-packages/libs/game at master · microsoft/pxt-common-packages](https://github.com/microsoft/pxt-common-packages/tree/master/libs/game)**
>
> master/libs/game

Some of the more fundamental language blocks (those in the logic, math, function, text, arrays, and loops categories) are in [pxt-core](https://github.com/microsoft/pxt).

Any blocks that do not compile to a function call in JavaScript (if/else, +/-/\*, create array, function blocks, etc.) are special and can’t be copied or modified. The ones that are function calls can be found in this folder:

> **[pxt/libs/pxt-common at master · microsoft/pxt](https://github.com/microsoft/pxt/tree/master/libs/pxt-common)**
>
> master/libs/pxt-common

---

<div class="post-metadata">

### Author: ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)
#### Post date: [November 30, 2021, 10:13pm UTC](https://forum.makecode.com/t/reporter-blocks-and-statement-blocks/11133/5 "2021-11-30T22:13:13Z")

</div>

If there are specific blocks you want to find, let me know and I can give more info.

---

<div class="post-metadata">

### Author: ![THEb0nny](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/theb0nny/32/3500_2.png) [@THEb0nny](https://forum.makecode.com/u/THEb0nny)
#### Post date: [December 1, 2021, 3:41pm UTC](https://forum.makecode.com/t/reporter-blocks-and-statement-blocks/11133/6 "2021-12-01T15:41:27Z")

</div>

I want to see a FOR loop block.  
I think that you can add the step value and the start value there (for some reason this value is simply indicated as 0 in the text of the block. Why)?  
I want to make a do while block. Why not? Then, when converting the code from js into blocks, there will be no problems.  
I also want to add a ternary operator to the logic if it works well. I just do not understand which file is needed.

---

<div class="post-metadata">

### Author: ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)
#### Post date: [December 1, 2021, 5:04pm UTC](https://forum.makecode.com/t/reporter-blocks-and-statement-blocks/11133/7 "2021-12-01T17:04:10Z")

</div>

Right, so those types of blocks are not something that can be added by an extension because they require changes to our blocks compiler/decompiler.

You can create an issue for those here: [https://github.com/microsoft/pxt-arcade/issues](https://github.com/microsoft/pxt-arcade/issues)

---

<div class="post-metadata">

### Author: ![THEb0nny](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/theb0nny/32/3500_2.png) [@THEb0nny](https://forum.makecode.com/u/THEb0nny)
#### Post date: [December 1, 2021, 7:24pm UTC](https://forum.makecode.com/t/reporter-blocks-and-statement-blocks/11133/8 "2021-12-01T19:24:48Z")

</div>

No, I work at ev3.  
It shouldn’t be in pxt-core?  
I do not understand where to look at the file to change the loop blocks and conditions.  
Is it possible to implement the ternary block of the condition so that it is visually the same as I did above?

---

<div class="post-metadata">

### Author: ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)
#### Post date: [December 1, 2021, 7:45pm UTC](https://forum.makecode.com/t/reporter-blocks-and-statement-blocks/11133/9 "2021-12-01T19:45:57Z")

</div>

We generally file issues in the repo for the editor. The link for ev3 is here: [https://github.com/microsoft/pxt-ev3/issues](https://github.com/microsoft/pxt-ev3/issues)

Language feature blocks are not defined using functions and `//%` annotations like the blocks you’ve posted, they are defined in code either in [this file](https://github.com/microsoft/pxt/blob/master/pxtblocks/blocklyloader.ts) or in [our fork of Blockly](https://github.com/microsoft/pxt-blockly).

Adding a new one involves making changes in a few place. The general process is:

1. Add the block localization info [here](https://github.com/microsoft/pxt/blob/master/pxtlib/blocks.ts#L313) in the appropriate category
2. Add the definition of the block in [blocklyloader](https://github.com/microsoft/pxt/blob/master/pxtblocks/blocklyloader.ts). There’s an init function for each of the categories where the blocks are defined.
3. Add the block to the toolbox definition [here](https://github.com/microsoft/pxt/blob/master/webapp/src/blocksSnippets.ts#L6)
4. Add compiler support for the block in [blocklycompiler](https://github.com/microsoft/pxt/blob/master/pxtblocks/blocklycompiler.ts)
5. Add decompiler support for the language feature in the [decompiler](https://github.com/microsoft/pxt/blob/master/pxtcompiler/emitter/decompiler.ts)
6. Add tests for both the [compiler](https://github.com/microsoft/pxt/tree/master/tests/blocklycompiler-test) and [decompiler](https://github.com/microsoft/pxt/tree/master/tests/decompile-test)

---

<div class="post-metadata">

### Author: ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)
#### Post date: [December 1, 2021, 7:51pm UTC](https://forum.makecode.com/t/reporter-blocks-and-statement-blocks/11133/10 "2021-12-01T19:51:25Z")

</div>

Here’s an example PR where I added `return` statements for function blocks:

> <https://github.com/microsoft/pxt/pull/6736/files>
>
> Test upload is \[here\](https://arcade.makecode.com/app/65da5855de9e6c3f90bbd68e1e…9a05d1114272ad-fec8cd5320).
> Relies on https://github.com/microsoft/pxt-blockly/pull/272
> 
> Adds return values for functions!
> 
> !\[2020-03-20 09 56 37\](https://user-images.githubusercontent.com/13754588/77187224-5eb5db00-6a91-11ea-9246-7f21737c496c.gif)
> 
> Looks great, but can it do recursion? Sure can!
> 
> \<img width="699" alt="Screen Shot 2020-03-20 at 10 26 36 AM" src="https://user-images.githubusercontent.com/13754588/77189817-68d9d880-6a95-11ea-9163-97c35c1fdaca.png"\>
> 
> Note that normally this does not emit return annotations for functions, but if you have a recursive function we emit a return type of \`any\`. This is just to stop TypeScript from complaining about "no implicit any". I chose not to emit any other return types in order to prevent our Blockly type checker from becoming even more complicated.
> 
> The build is going to fail until the pxt-blockly changes are merged and bumped.
> 
> Some things that can be improved:
> 1. Error messages are pretty bad when you do something that isn't TypeScript compatible
> 2. We should support any function argument type. Recursion works right now because all function output blocks have their type check set to "any"

---

<div class="post-metadata">

### Author: ![THEb0nny](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/theb0nny/32/3500_2.png) [@THEb0nny](https://forum.makecode.com/u/THEb0nny)
#### Post date: [December 1, 2021, 9:39pm UTC](https://forum.makecode.com/t/reporter-blocks-and-statement-blocks/11133/11 "2021-12-01T21:39:33Z")

</div>

Sounds very difficult … 😃  
Of course, there are a lot of problems on ev3 without this after the update, when you tried to raise the pxt version. 🙂  
Therefore, it will probably remain for now. We must try to solve the problems with the blocks and the simulator. ☹
