# Code is not executed in Processing, but in p5.js Web Editor

**URL:** https://discourse.processing.org/t/code-is-not-executed-in-processing-but-in-p5-js-web-editor/34867
**Category:** Beginners
**Created:** [January 27, 2022, 11:05pm UTC](https://discourse.processing.org/t/code-is-not-executed-in-processing-but-in-p5-js-web-editor/34867 "2022-01-27T23:05:37Z")
**Posts on this page:** 1
**Showing post:** 6

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [January 28, 2022, 12:44pm UTC](https://discourse.processing.org/t/code-is-not-executed-in-processing-but-in-p5-js-web-editor/34867/6 "2022-01-28T12:44:57Z")

</div>

> [@Master\_Kneater](#):
>
> … I packed the function into the **preload()**. Unfortunately that didn’t change anything either.

Callback **preload()** only works for p5js asset loading functions such as **loadImage()**, **loadJSON()**, **loadFont()**, etc.

Also for addon libraries which internally register their own loading functions into the p5js such as [**loadSound()**](https://p5js.org/reference/#/p5/loadSound) from the p5.sound library.

Anything else **preload()** won’t await for them to get fully finished!

> [@Master\_Kneater](#):
>
> Is there a way to execute the exact `deviceList[1].id` only once it exists?

Yes, many ways! But IMO the easiest approach would be to postpone the automatically initialization of the p5js library until your callback **getDevices()** has finished its job.

When p5js library is loaded it searches for callbacks **setup()** & **draw()** in the browser’s global context.

So the trick to cancel that is to hide both **setup()** & **draw()** until all your unregistered loadings have been finished.

In order to hide both **setup()** & **draw()** we’ll have to slightly modify their function declaration so they won’t automatically go into the global context:

Instead of `function setup() {}` go w/ `const setup = function () {};`.

Same for `function draw() {}`. Just replace it w/ `const draw = function () {};`.

Let’s now create a function which will manually start the p5js library:

```auto
function startP5() {
  globalThis.setup = setup; // place callback setup() into global context
  globalThis.draw = draw; // place callback draw() into global context

  new p5; // manually instantiate the p5js library
}

```

Invoke **startP5()** at the end of **getDevices()** callback after its _devices[]_ loop:

And of course move your _navigator_ loading stuff out of callback **preload()**, b/c it won’t be automatically called back until p5js is manually started. 😉

P.S.: You won’t be able to access anything from the [p5js API](https://p5js.org/reference/) until after you invoke **startP5()**. ⚠

---

_[View the full topic](https://discourse.processing.org/t/code-is-not-executed-in-processing-but-in-p5-js-web-editor/34867)._
