Groovy List Help

I am new to groovy (and java derivatives) and am having a difficult time figuring out how to define a list of values, and then reference it below within a different function. I have been reading http://www.groovy-lang.org/groovy-dev-kit.html#Collections-Lists for reference.

def presetValues = [20,60,80]

def lowPreset() {
log.debug “low preset”
//setLevel(presetValues[0])
//setLevel(presetValues.get(0))
//setLevel(presetValues.getAt(0))
}

The above setLevel calls are giving me the following errors:
Cannot invoke method get() on null object
Cannot invoke method getAt() on null object

any help is greatly appreciated

def preset is not defined within the method lowPreset, so it’s out of scope
Use state instead ie: state.presetValues = [blablabla]

Mike’s response is correct (stashing stuff in state will work), but there may be cases where you don’t want to store values persistently, or want a function to be able to operate on different sets of data. In that case you can pass the values into the function. For example:

def exampleFunction() {
  def presetValues = [20, 60, 80]
  setLowest(presetValues)
}

def setLowest(valueList) {
  setLevel(valueList.min())
}