Did you know that its a good idea to use global function and variables when you use event in your code.
Have a look at example below :-
You will not be able to call GetActiveQueueMessage function and your script just dies.
Key take from this is, if you have event, any variable or function you're referring to, please make sure its defined on global or script scope.
Otherwise, you pretty much get uninitialized or empty variable everywhere.