Can't seem to draw in the setup function (beginner question)

I’m using the p5.js web editor and can’t seem to get anything drawn to the screen using setup(). It does work in draw() though.
Oddly I tested copy/pasting code in from the setup() reference page and it works when I copy that code. If I write the exact same code myself it does not work.
Any idea what could be happening?

I tried the code you showed the the post above and in both it worked for me.

I have tried version p5js V1 and V2 and switched off autosave off but both versions of the code create a red background so I have no idea what is happening when you do it.

1 Like

Hi!
Can you save the sketch with the code you are having trouble with, exactly as you have typed it, and then post the URL here?

Having access to your exact code and exact environment will make it much easier for people to help you.

(There’s a lot that a screenshot doesn’t capture, such as any error messages you may be getting in the console, sketch settings, non-printing characters, etc)

Update:

Here’s a working sketch I’ve saved with your code so you have more to compare with:

However, please do share the URL of your own saved sketch even if the above one works for you. You can learn a lot from the little issues.

1 Like

Hi! Thanks for the taking the time. I tried yours and it works. I really don’t know what I may have been doing wrong.

Just wondering if you pressed run after changing it.

1 Like

Also not having auto-refresh box checked

1 Like