Thread: Keeping Track
View Single Post
Whay about an an event handler?
Old
chuck
Guest
 
Status:
Posts: n/a
Default Whay about an an event handler? - 02-27-2006, 04:29 PM

I'm not sure of your programing experience, so please don't be insulted if the following seems obvious, but I hope it helps.

In event driven programming a true event consists of an event trigger and an event handler. An event trigger is the condition that causes an event to occur. An event handler is a method that runs whenever the trigger occurs. Events can often take the place of complicated or convoluted logic in a program.

I suggest you combine an Alice event that checks for the trigger with an Alice method to handle what happens when the trigger occurs. In your particular case, you could:

1. Set up a method to do whatever you want to do when the mouse is clicked on a particular object. To keep score, you could set up a variable as a property of an object, or as a property of the world itself. When the method runs, the score varibale could be incremented or otherwise changed.

2. Set up an event of the form:
When the mouse is clicked on (something) do (method name)

Put the object in place of (something) and the method described
above in place of (method name).

The method coud do one thing, do several things, or call other methods from within itself, which would be the proper way to layer software modules.

You could also set up an event of the form:

When something is true

to cause whatever actions you desire when the score variable reaches a certain value.For example:

When (score > 100) becomes true, do (world.victory)

Chuck Herbert
   
Reply With Quote