Can lists and subroutine handlers mix?

I have been trying to store subroutine handlers in a list, without calling the subroutines when the list is set.
There ia an old Mac Observer article stating that this used to be possible.
Mac Observer subroutine article

It seems that this code should work, but it does not.
I would be grateful if someone could offer a suggestion as to how I could make something along these lines work.

Thanks


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

You have the right principle, but the variables you use to access the handlers have to be globals.

on check_triggerList for posKey

  global routine1, routine2, routine3, routine 4, new_routine
  
  set triggerList to {"test1", "test2", "test3", "test4"} --list of possible triggers
  set routineList to {routine1, routine2, routine3, routine4} --subroutine calls

  repeat with t from 1 to the count of triggerList --goes through the triggerList to find a reference number
    if item t of triggerList is posKey then
      set new_routine to item t of routineList
      new_routine()
    end if
  end repeat

end check_triggerList

That worked great. Gave me a bit of trouble because I had not noticed that you had made new_routine a global as well.
My lack of attention to detail will be the death of me some day.

Thanks again.