As there is no event section in the manual yet:
1. To make an event handler you need to wrap your code in
Code: Select all
function myEventHandlerOnLowEnergy( eventName )
( ... your code goes here ... )
end
2. put the name of the event (the string that is being used in raiseEvent("lowEnergy")) into the event list of the script that is going to act as an event handler for this event. Note that many scripts can define event handlers for your "lowEnergy" event in which case they'll all be called if such an event is raised.
3. And now comes the critical part: the *NAME* of the script has to be *identical* with the name of the event handler function inside this script. Otherwise the event system cannot know which script to call.
Consequently: script name=myEventHandlerOnLowEnergy
event (to be put in the list) = lowEnergy
Then add above code into the script of the script. Then you are done.
Hope this helps.
PS: What I assume happens in your case is that your code gets run as part of the global script space at a time before the variables have been defined. Normally, there is a strict order in mudlet items that items get processed from top to bottom, but scripts are different in this respect, as well as that scripts normally need proper function definitions unless you explicitely want to make this code globally available e.g. for variables. Without a function definition your code simply gets run once and never again unless you press compile -> necessity for function declarations.