Microsoft MakeCode

Reporter blocks and Statement blocks

Privet, ya khochu poprobovat’ sozdat’ blok operatora ?: YA smotryu dokumentatsiyu 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
but I don’t understand how the sample code works.
I copied and pasted to 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;

but i got error on pop and on _popStatement.

Can you provide a clearer example?

1 Like

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.

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

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

1 Like

@THEb0nny what blocks specifically are you trying to find? Most blocks for arcade are in pxt-common-packages in this folder:

Some of the more fundamental language blocks (those in the logic, math, function, text, arrays, and loops categories) are in pxt-core.

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:

1 Like

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

1 Like

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.

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:

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?

We generally file issues in the repo for the editor. The link for ev3 is here:

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 or in our fork of Blockly.

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

  1. Add the block localization info here in the appropriate category
  2. Add the definition of the block in blocklyloader. There’s an init function for each of the categories where the blocks are defined.
  3. Add the block to the toolbox definition here
  4. Add compiler support for the block in blocklycompiler
  5. Add decompiler support for the language feature in the decompiler
  6. Add tests for both the compiler and decompiler

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

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