Missing language/ library?

Hey, I tride to copy a code from p5 preferences to make a button. I got some error saying some of the codewords were missing. Im wondering if there is some library or language I’m missing.

var button

function setup() {
  createCanvas(300,400)
}

function draw() {
  background(155)
  button1 = createButton('1')
  button.position (20,300)
  button.mousePressed(background(255,0,0))
}

also, if you know any other ways to make a button, I would be happy to hear about them:)

just realized I called the button for button1, but still doesn’t work…

hi, createButton needs Dom library.

<script type="text/javascript" src="p5.dom.js"></script>

and for button.mousePressed()
https://p5js.org/reference/#/p5.Element/mousePressed

or something like

button.mousePressed(backgroundChange);

function backgroundChange() {
   ...
}
1 Like