# Couple of questions making a PXT

**URL:** https://forum.makecode.com/t/couple-of-questions-making-a-pxt/2333
**Category:** PXT
**Created:** [June 7, 2020, 6:59am UTC](https://forum.makecode.com/t/couple-of-questions-making-a-pxt/2333 "2020-06-07T06:59:46Z")
**Posts on this page:** 19
**Page:** 1

<div class="post-metadata">

### Author: ![jfo8000](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jfo8000/32/1038_2.png) [@jfo8000](https://forum.makecode.com/u/jfo8000)
#### Post date: [June 7, 2020, 6:59am UTC](https://forum.makecode.com/t/couple-of-questions-making-a-pxt/2333/1 "2020-06-07T06:59:46Z")

</div>

I am looking at making a PXT to wrap a javascript library - was tossing up between this and doing my own blockly. Basically I am experimenting with a 3d asset generator to make 3d printable objects.

I have gotten pretty far quickly, which is great but I am a bit stuck and going round in circles in the documentation.

1. I want every new application to have “on start”

- how do I make sure a block is always on the code editor
- how do I trigger code based off “on start”

1. When I do pxt serve, half the icons are missing, especially the ones in the “Simulator Toolbar” for play, stop and debug. Is this something I will have to make on my own or is this just a bug running locally on my machine?
2. Am I able to control the size of the Simulator window to be a bit taller?

Thanks for any help!  
JFo

---

<div class="post-metadata">

### Author: ![jfo8000](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jfo8000/32/1038_2.png) [@jfo8000](https://forum.makecode.com/u/jfo8000)
#### Post date: [June 7, 2020, 11:37pm UTC](https://forum.makecode.com/t/couple-of-questions-making-a-pxt/2333/2 "2020-06-07T23:37:00Z")

</div>

The answer to question 2 is I had a typescript error.  
When typescript errors occur you fall back to an unthemed thing - which means you can’t see the icons.

The base pxtsim.d.ts had errors so I added off “skipLibCheck”: true in pxt-sample/sim/tsconfig.json. This quieted down these errors:

```
../node_modules/pxt-core/built/pxtsim.d.ts(256,13): error TS1086: An accessor cannot be declared in an ambient context.
../node_modules/pxt-core/built/pxtsim.d.ts(1010,13): error TS1086: An accessor cannot be declared in an ambient context.
../node_modules/pxt-core/built/pxtsim.d.ts(1049,13): error TS1086: An accessor cannot be declared in an ambient context.
../node_modules/pxt-core/built/pxtsim.d.ts(1294,21): error TS1086: An accessor cannot be declared in an ambient context.
../node_modules/pxt-core/built/pxtsim.d.ts(1294,21): error TS7033: Property 'stoppedClass' implicitly has type 'any', because its get accessor lacks a return type annotation.
../node_modules/pxt-core/built/pxtsim.d.ts(1295,21): error TS1086: An accessor cannot be declared in an ambient context.
../node_modules/pxt-core/built/pxtsim.d.ts(1295,21): error TS7033: Property 'invalidatedClass' implicitly has type 'any', because its get accessor lacks a return type annotation.
INTERNAL ERROR: Error: Exit code: 2 from cd sim; node ../node_modules/typescript/bin/tsc
    at ChildProcess.<anonymous> (/Users/jessica/Documents/Me3d/KhanCoding/pxt-sample/node_modules/pxt-core/built/nodeutil.js:85:24)
    at ChildProcess.emit (events.js:223:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
```

---

<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: [June 8, 2020, 5:12pm UTC](https://forum.makecode.com/t/couple-of-questions-making-a-pxt/2333/3 "2020-06-08T17:12:40Z")

</div>

Answer to 1:

- You can customize the starting blocks by changing `libs/blocksprj/main.blocks` in your target repo. The one for arcade is [here](https://github.com/microsoft/pxt-arcade/blob/master/libs/blocksprj/main.blocks)
- To make it so that on-start can never be deleted, enable the option [onStartUnDeletable](https://github.com/microsoft/pxt/blob/master/localtypings/pxtarget.d.ts#L124) in the runtime settings in `pxtarget.json`

Answer to 3:

- In the simulator settings in `pxtarget.json`, there is an [aspectRatio](https://github.com/microsoft/pxt/blob/master/localtypings/pxtarget.d.ts#L187) setting that you can use to make the sim taller

---

<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: [June 8, 2020, 5:19pm UTC](https://forum.makecode.com/t/couple-of-questions-making-a-pxt/2333/4 "2020-06-08T17:19:35Z")

</div>

Also, on-start is just a wrapper for the “top level” code in main.ts. Any code that’s placed in there should run at the start of the program. If you’re trying to make your own custom on-start event that you can control, (e.g. `myNamespace.onStart(() => {})`), then you should define your own function and remove the onStart block entirely. You can make any block undeletable by setting this option:

```auto
//% undeletable=1

```

and you can make your custom block show up in the default project by editing that `main.blocks` file I mentioned in my above comment. For example, if you set the blockId of your function to be `blockId=myCustomOnStart` then your `main.blocks` should look like this:

```auto
<xml xmlns="http://www.w3.org/1999/xhtml">
  <variables></variables>
  <block type="myCustomOnStart" x="0" y="0"></block>
</xml>

```

---

<div class="post-metadata">

### Author: ![Dwagga](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dwagga/32/987_2.png) [@Dwagga](https://forum.makecode.com/u/Dwagga)
#### Post date: [June 25, 2020, 4:42pm UTC](https://forum.makecode.com/t/couple-of-questions-making-a-pxt/2333/5 "2020-06-25T16:42:57Z")

</div>

Hello @jfo8000 and @richard! I’m a begginer as well and I’m building my own PXT. I would like to know if:

1. Does PXT allow accessing the C++ code behind the blocks?
2. I would like to have my own set of blocks, with their customised C++ code, is that possible in any way?

Thanks!

---

<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: [June 25, 2020, 4:49pm UTC](https://forum.makecode.com/t/couple-of-questions-making-a-pxt/2333/6 "2020-06-25T16:49:16Z")

</div>

You can do so by developing an extension: [https://makecode.com/extensions](https://makecode.com/extensions)

However, you should ask yourself if you need to use C++ for your extension. If possible, it is better to implement everything in TypeScript. That will make your code more portable, debuggable, and will allow your code to run in the simulator.

For examples of extensions that use C++, check out [pxt-common-packages](https://github.com/microsoft/pxt-common-packages).

May I ask what you want to make your own editor for? If it’s just to support a new board, consider [adding it to maker](https://maker.makecode.com/boards/add-a-new-board) instead.

---

<div class="post-metadata">

### Author: ![Dwagga](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dwagga/32/987_2.png) [@Dwagga](https://forum.makecode.com/u/Dwagga)
#### Post date: [June 25, 2020, 5:42pm UTC](https://forum.makecode.com/t/couple-of-questions-making-a-pxt/2333/7 "2020-06-25T17:42:47Z")

</div>

Thanks for the reply @richard.

You are right, and maybe what I want to do is easier than I thought. I would like to build a centrifuge. I’m using the board Adafruit feather M4 and my goal is to run the motor of the centrifuge by using the blocks in PXT.  
The block I want to create will have 2 different variables the user can modify: Time and speed. An example could be: ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/2/2ce89c91577de74369a592bf1c5e22f89d4f5d56.png)  
So, how can I “link” the block input given by the user with the hardware (centrifuge motor)? I know the question may sound very general, but any tip or help would be fantastic for me to start working on it.

Thanks

---

<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: [June 25, 2020, 6:07pm UTC](https://forum.makecode.com/t/couple-of-questions-making-a-pxt/2333/8 "2020-06-25T18:07:27Z")

</div>

Great! The Adafruit Feather M4 express is one of the boards supported on [maker.makecode.com](http://maker.makecode.com)

For defining blocks, check out our docs [here](https://makecode.com/defining-blocks). Every block corresponds to a TypeScript function which you can use to implement all of the communication with the centrifuge.

How does the board communicate with the centrifuge? We have typescript APIs for i2c and spi under the `pins` namespace along with all of the usual analog and digital read/write.

---

<div class="post-metadata">

### Author: ![Dwagga](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dwagga/32/987_2.png) [@Dwagga](https://forum.makecode.com/u/Dwagga)
#### Post date: [June 28, 2020, 2:49pm UTC](https://forum.makecode.com/t/couple-of-questions-making-a-pxt/2333/9 "2020-06-28T14:49:12Z")

</div>

Hi @richard! Thanks for your answer, it’s really helpful.  
To run the centrifuge I use the library Servo.h.  
This is the code:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/0/0afb4b2667b7b0250d1cc974f6f19321d491de1f.png)

The brushless motor attached to the pin 8 can be run like a servo motor, where 0 is the minimum power and 180 the maximum.  
Any tip to create my TypeScript function to implement this code?  
How can the typeScript code read the inputs Speed and time from the block? (see block image above)

Thanks!

---

<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: [July 2, 2020, 10:50pm UTC](https://forum.makecode.com/t/couple-of-questions-making-a-pxt/2333/10 "2020-07-02T22:50:24Z")

</div>

@peli any advice for using servos with makecode?

---

<div class="post-metadata">

### Author: ![peli](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/peli/32/12_2.png) [@peli](https://forum.makecode.com/u/peli)
#### Post date: [July 5, 2020, 1:23pm UTC](https://forum.makecode.com/t/couple-of-questions-making-a-pxt/2333/11 "2020-07-05T13:23:43Z")

</div>

Have you looked at the servo library for ideas? [https://github.com/microsoft/pxt-common-packages/blob/master/libs/servo/servo.ts](https://github.com/microsoft/pxt-common-packages/blob/master/libs/servo/servo.ts)

---

<div class="post-metadata">

### Author: ![Dwagga](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dwagga/32/987_2.png) [@Dwagga](https://forum.makecode.com/u/Dwagga)
#### Post date: [August 3, 2020, 4:23pm UTC](https://forum.makecode.com/t/couple-of-questions-making-a-pxt/2333/12 "2020-08-03T16:23:29Z")

</div>

@peli @richard I’m struggling with the addition of my blocks to my local editor. I’ve got a MakeCode Maker editor type and, after the installation, I have 3 folders: _pxt_, _pxt-common-packages_ and _pxt-maker_. In which folder and file should I paste my blocks code to visualize them in the editor? Am I doing something wrong?

Thanks!

---

<div class="post-metadata">

### Author: ![peli](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/peli/32/12_2.png) [@peli](https://forum.makecode.com/u/peli)
#### Post date: [August 3, 2020, 4:37pm UTC](https://forum.makecode.com/t/couple-of-questions-making-a-pxt/2333/13 "2020-08-03T16:37:15Z")

</div>

@dwagga are you creating a fork of the maker editor? or just adding a few blocks to it. If you just need to add a few blocks, you can add them without forking the editor. See [https://arcade.makecode.com/blocks/custom](https://arcade.makecode.com/blocks/custom)

---

<div class="post-metadata">

### Author: ![Dwagga](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dwagga/32/987_2.png) [@Dwagga](https://forum.makecode.com/u/Dwagga)
#### Post date: [August 3, 2020, 9:35pm UTC](https://forum.makecode.com/t/couple-of-questions-making-a-pxt/2333/14 "2020-08-03T21:35:09Z")

</div>

@peli You are right, I don’t need to create a fork. I’ve been trying to do it through an extension: creating the blocks in the file _main.ts_ of the extension and adding it to the project. Is that correct? However, after adding it, don’t see the blocks in the editor. What do you think?  
Moreover, how can I make an extension compatible with a specific board? For example, when I try to add the extension in a project that has an Adafruit Feather M4 Express, it says:

_Extension adafruit-feather-m4-express is incompatible with pxt-centrifuge2. Remove adafruit-feather-m4-express and add pxt-centrifuge2?_

---

<div class="post-metadata">

### Author: ![peli](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/peli/32/12_2.png) [@peli](https://forum.makecode.com/u/peli)
#### Post date: [August 4, 2020, 12:40am UTC](https://forum.makecode.com/t/couple-of-questions-making-a-pxt/2333/15 "2020-08-04T00:40:21Z")

</div>

Do you have a repo we can look at?

---

<div class="post-metadata">

### Author: ![Dwagga](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dwagga/32/987_2.png) [@Dwagga](https://forum.makecode.com/u/Dwagga)
#### Post date: [August 4, 2020, 10:23am UTC](https://forum.makecode.com/t/couple-of-questions-making-a-pxt/2333/16 "2020-08-04T10:23:35Z")

</div>

Hello @peli@richard. Yes, my extension is: [https://github.com/Dwagga/pxt-centrifuge2](https://github.com/Dwagga/pxt-centrifuge2)  
I got an error when it tries to build. Could you please take a look? I’m simply trying to add two basic blocks, made with [https://makecode.com/playground](https://makecode.com/playground). Maybe there is something wrong with the dependencies.

Thank you!

---

<div class="post-metadata">

### Author: ![peli](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/peli/32/12_2.png) [@peli](https://forum.makecode.com/u/peli)
#### Post date: [August 4, 2020, 3:58pm UTC](https://forum.makecode.com/t/couple-of-questions-making-a-pxt/2333/17 "2020-08-04T15:58:50Z")

</div>

The extension loads for me when i add it as an extension in maker.  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/a/a42b5baf2aa5db1b46729d9576521c341293afc4.png)

---

<div class="post-metadata">

### Author: ![Dwagga](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dwagga/32/987_2.png) [@Dwagga](https://forum.makecode.com/u/Dwagga)
#### Post date: [August 4, 2020, 4:55pm UTC](https://forum.makecode.com/t/couple-of-questions-making-a-pxt/2333/18 "2020-08-04T16:55:29Z")

</div>

Right, it works. However I got this error, should I worry about it?

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/0/04c048ea529eb35ab979617e7ead7bf059158158.png)

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/2/2145872390229feb86e32cd48f16b9ebaa1603fb.png)

Thanks!

---

<div class="post-metadata">

### Author: ![jfo8000](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jfo8000/32/1038_2.png) [@jfo8000](https://forum.makecode.com/u/jfo8000)
#### Post date: [August 4, 2020, 8:54pm UTC](https://forum.makecode.com/t/couple-of-questions-making-a-pxt/2333/19 "2020-08-04T20:54:20Z")

</div>

Just a followup on this one. I tried undeleteable, but because I hadn’t removed onStart from the blocks list, the user could drag a second one out and then not be able to delete. So I gave up and just went half way with the onStart starting block.

Am pretty happy with the compromise, though.  
JFo
