Multiple event handling blocks?

Started by
0 comments, last by Endar 16 years, 5 months ago
This is probably a pretty simple question but I was just wondering if there is some sort of coding technique that people use to avoid having insanely complex event handling structures. At first I actually put effort into integrating all my user input into one place, but its starting to seem less and less worthwhile as my program moves along. To take a simple example say the code that you run after a left click depends on where exactly you left click the mouse, and further that there are many different options on what to do in a given situation. As it stands I have a series of flags that check this that and the other to determine what the situation is, but as the number of different possible situations increase my event handling gets more and more confusing. So to that end, would it be a good idea to create different event handling structures in different places? What is typically done to combat this problem? Thanks in advance for any help.

I'm working on a game! It's called "Spellbook Tactics". I'd love it if you checked it out, offered some feedback, etc. I am very excited about my progress thus far and confident about future progress as well!

http://infinityelephant.wordpress.com

Advertisement
Ideally, you should be getting input in a single place, sending that as an event and then having your app deal with the input.

Just say we got an event for a mouse click at point (x,y). When your app receives that event, it has to check what was clicked on. If you're working on a game, you would usually have a lower layer than encompasses a game state, and the event would get sent to that. So, you're either in a menu, or playing the game and you can check from there.

If you're playing a game, you have the game state check if a button was clicked on, or a unit, or if the player fired or not. If you're in a menu, you have the menu check if the point clicked on was a button or not and then go from there.
[size="2"][size=2]Mort, Duke of Sto Helit: NON TIMETIS MESSOR -- Don't Fear The Reaper

This topic is closed to new replies.

Advertisement