# What causes the simulator to generate this error? The code works in the board hardware fine

**URL:** https://forum.makecode.com/t/what-causes-the-simulator-to-generate-this-error-the-code-works-in-the-board-hardware-fine/15610
**Category:** Arcade
**Created:** [September 26, 2022, 5:01pm UTC](https://forum.makecode.com/t/what-causes-the-simulator-to-generate-this-error-the-code-works-in-the-board-hardware-fine/15610 "2022-09-26T17:01:09Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![xjordanx](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/xjordanx/32/6537_2.png) [@xjordanx](https://forum.makecode.com/u/xjordanx)
#### Post date: [September 26, 2022, 5:01pm UTC](https://forum.makecode.com/t/what-causes-the-simulator-to-generate-this-error-the-code-works-in-the-board-hardware-fine/15610/1 "2022-09-26T17:01:09Z")

</div>

![Error_pin_](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/1/150bcac7674a0ff4a17feee7b90ade5ca7fe163b.png)  
I suspect it’s because I have to use the Micro:Bit Card Edge extension to enable PIN functions, yet my board is a RP2040 based custom board and the pin functions actually work with the GPIO as I’m using it…

---

<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: [September 26, 2022, 5:30pm UTC](https://forum.makecode.com/t/what-causes-the-simulator-to-generate-this-error-the-code-works-in-the-board-hardware-fine/15610/2 "2022-09-26T17:30:51Z")

</div>

This means that the API isn’t defined in the simulator.

> **A more detailed explanation**
>
> When a project is compiled in MakeCode, we first convert the TypeScript of the project into an intermediate representation. This representation is either sent to the binary compiler to produce machine code (a UF2 file), or sent to the simulator compiler to produce a JavaScript file that mimics our C++ runtime. You can actually see this file if you switch to JavaScript and look at the “built” tab in the file explorer underneath the simulator, it’s called `binary.js`. That takes care of all of the TS code from the user and their added extensions, but the C++ code from extensions is _not_ compiled and run in the browser. Instead, we implement “shim” functions that mimic the behavior of the C++ functions.
> 
> For example, the `drawImage` function in pxt-arcade is implemented in C++ inside the `screen` extension in pxt-common-packages [here](https://github.com/microsoft/pxt-common-packages/blob/master/libs/screen/image.cpp#L837).
> 
> When we compile that extension, we generate a `shims.d.ts` file that contains a TS typing for that API [here](https://github.com/microsoft/pxt-common-packages/blob/master/libs/screen/shims.d.ts#L118). This is the typing that is used by the compiler to check the user code, but it is just a typing with no implementation.
> 
> If we look at the `binary.js` for an arcade program that references this API, you’ll see something like this:
> 
> ```auto
> case 25:
> r0 = s.retval;
> s.dw___9800 = (r0);
> r0 = s.arg0.fields["img"];
> s.tmp_0 = r0;
> r0 = pxsim_ImageMethods.drawImage(globals.screen ___1829, s.tmp_0, s.rxl___ 9790, s.ry___9702);
> r0 = (s.rxl ___9790 + s.dw___ 9800);
> s.tmp_0 = r0;
> r0 = (s.tmp_0 % s.w___9680);
> s.rxl___9790 = (r0);
> 
> ```
> 
> that call to `pxsim_ImageMethods.drawImage` will end up calling [this function](https://github.com/microsoft/pxt-common-packages/blob/master/libs/screen/sim/image.ts#L379) which is defined inside of the `sim` folder of screen extension. This function is written by hand and mimics the same C++ function but using APIs in the browser rather than C++.

If you’re writing a C++ extension, the APIs you add will not work in the simulator. We don’t allow third-party extensions to contribute code to the simulator for security reasons; the code does not pass through our compiler so we cannot guarantee that it is not malicious in some way. This is why we generally recommend that all APIs be written in TypeScript whenever possible.

If you aren’t writing a C++ extension and just happened to hit this when calling some API from pxt-arcade or one of the recommended extensions, you should [open an issue](https://github.com/microsoft/pxt-arcade/issues) since this is most likely a bug!

---

<div class="post-metadata">

### Author: ![xjordanx](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/xjordanx/32/6537_2.png) [@xjordanx](https://forum.makecode.com/u/xjordanx)
#### Post date: [September 26, 2022, 7:37pm UTC](https://forum.makecode.com/t/what-causes-the-simulator-to-generate-this-error-the-code-works-in-the-board-hardware-fine/15610/3 "2022-09-26T19:37:57Z")

</div>

I am ONLY using Typescript/blockly. I’m able to do this because of the RP2040 support that’s been added by Michal recently. I’m using the final public test build editor.

So what could be causing this? I guess it’s safe to ignore while things work on the board but it does mean I have no debug capability…

---

<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: [September 26, 2022, 7:38pm UTC](https://forum.makecode.com/t/what-causes-the-simulator-to-generate-this-error-the-code-works-in-the-board-hardware-fine/15610/4 "2022-09-26T19:38:36Z")

</div>

can you share some code? my guess is it’s a bug on makecode’s side. if you can share a project that reproduces this error than I can take a look

---

<div class="post-metadata">

### Author: ![xjordanx](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/xjordanx/32/6537_2.png) [@xjordanx](https://forum.makecode.com/u/xjordanx)
#### Post date: [September 26, 2022, 8:47pm UTC](https://forum.makecode.com/t/what-causes-the-simulator-to-generate-this-error-the-code-works-in-the-board-hardware-fine/15610/5 "2022-09-26T20:47:14Z")

</div>

I’ve published to the following repo:

> **[GitHub - xjordanx/badge\_test: A MakeCode project](https://github.com/xjordanx/badge_test)**
>
> A MakeCode project. Contribute to xjordanx/badge\_test development by creating an account on GitHub.

---

<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: [September 26, 2022, 11:57pm UTC](https://forum.makecode.com/t/what-causes-the-simulator-to-generate-this-error-the-code-works-in-the-board-hardware-fine/15610/6 "2022-09-26T23:57:17Z")

</div>

thanks @xjordanx, that is definitely a makecode bug. looks like it isn’t generating a declaration for that particular pin for some reason. sorry for the inconvenience!

in the meantime, you can work around it like so:

```typescript
if (control.deviceDalVersion() !== "sim") {
    pins.P23.setPull(PinPullMode.PullDown)
    pins.P24.setPull(PinPullMode.PullDown)
}

```
