How to reference context?

I have defined a frame environment and want to reference the counter in the title of the frame but it gives me an error as the counter is context. Is there a way to get around this?
My current version is below. Basically everything works but if I enter a label my frame it tells me it cant reference context.


#let frame(content, counter: none, title: none, fill-body: none, fill-header: none, radius: 0.2em, color: default-color,type : none,label:none) = {

  // Automatically increment frame counter
let displayed-counter = none

if type == "Lemma" {
  lemma-counter.step()
  displayed-counter = if counter == none {
    context lemma-counter.display() 
    color = gray
  } else {
    counter
  }

} else if type == "Definition" {
  definition-frame-counter.step()
  displayed-counter = if counter == none {
    context definition-frame-counter.display()

    color= green
  } else {
    counter
  }

} else if type == none {
  displayed-counter = if counter == none {
    context definition-frame-counter.display()
  } else {
    counter
  }
}

  let header = none

  if fill-header == none and fill-body == none {
    fill-header = color.lighten(75%)
    fill-body = color.lighten(85%)
  }
  else if fill-header == none {
    fill-header = fill-body.darken(10%)
  }
  else if fill-body == none {
    fill-body = fill-header.lighten(50%)
  }

  if radius == none {
    radius = 0pt
  }

 
  if title == none {
    header = [*#type #displayed-counter#label*]
  } else {
    header = [*#type #displayed-counter#label
    * #title]
  }
  
  show stack: set block(breakable: false, above: 0.8em, below: 0.5em)

  stack(
    block(
      width: 100%,
      inset: (x: 0.4em, top: 0.35em, bottom: 0.45em),
      fill: fill-header,
      radius: (top: radius, bottom: 0cm),
      header,
    ),
    block(
      width: 100%,
      inset: (x: 0.4em, top: 0.35em, bottom: 1em),
      fill: fill-body,
      radius: (top: 0cm, bottom: radius),
      content,
      
    ),
    v(0.21cm)
  )
}

Welcome to the forum!

Unfortunately, the code you posted is incomplete. There may be more things missing from it, but here’s a start:

  1. frame() is never called - is it important what arguments it has? How are you wanting to use it?
  2. No default-color exists → compilation error
  3. No definition-frame-counter → compilation error

Please see https://www.sscce.org/ for some of the how and the why of posting a good code example.