Why is the rectangle not showing on the widget?

122 views Asked by At

Since I am still learning the basics of JavaScript, can someone suggest me a possible way to solve the error of this Scriptable code? (I am trying to draw a simple rectangle at the centre of the widget).

Please, I don’t want to write the solution code, but to explain me, if possible, what I have done wrong and how can I do it better, after all, as I said, I am still learning the new language.

CODE:

async function createCentralRect(w, h) {
  let newRect = new Rect(0, 0, w, h)
  return newRect
}

async function createWidget() {
  let widget = new ListWidget()

  let rect = await createCentralRect(2, 2)
  let cnv = new DrawContext()
  let rectColor = new Color("#000")
  cnv.fillRect(rect)
  cnv.setFillColor(rectColor)
  return widget
}

let widget = await createWidget()
if (config.runsInWidget) {
  Script.setWidget(widget)
} else {
  widget.presentSmall()
}
0

There are 0 answers