PDA

View Full Version : Help with Problem 8 on Speed Control PLEASE


videogamephreak
03-25-2008, 06:00 PM
I am having a lot of trouble with this problem. I cannot figure out how to make the fan stop when I click the off button. I know it has something to do with a world variable. Can anyone guide me through this problem and the general layout in solving it? Thanks much.

lanceA
03-25-2008, 09:56 PM
The fan Object has several buttons, including one called .offButton. You probably need to create several events based upon which button on the fan is clicked (sort of like: if mouse is clicked on offButton, etc. do something, i.e. call a method that handles actions to be preformed when any button is pressed.

Then you have a method that is basically a large if/else if statement.

if button == fan.highButton
...do something
else
if button == fan.offButton
...do NOTHING in other worlds, there is no code for this if statement
else
if button -- fan.lowButton
... do something

etc., etc.

If you stop and think about the logic involved, it is fairly simple.

Good luck,

videogamephreak
03-26-2008, 12:29 AM
Ok I understand things a little better now. I know about the event handlers and how you have to assign them to the buttons on the fan. However, I'm still a bit confused on a few things.

For the off button in the event handlers what do I have that assigned to?

"When mouse is clicked on fan.offButton, do .......?"

What would I put in for the dots? I'm really not to sure if I make a method for the off button or not. Like, what code would I put in there for that?

lanceA
03-26-2008, 04:14 PM
I would create a class level method called something like fan.clicked(Object button) which my click event would call and pass the button that was clicked. Then I would probably just have an If/Else statement that followed along these lines:
if button == fan.buttonHigh
while fan.buttonDown == fan.buttonhigh
//rotate the blades

Else
if button == fan.buttonOff
//put no code here

Else
if button == fan.buttonSlow
//place code here to control speed of blades
// use a while-loop similar to that for the fan.buttonHigh above

Else
if //add other code here for each button on the fan

Your event handlers will call this click() method each time a button is pressed on the fan.

That's one way of doing it, but I'm sure 5 different programmers would probably code it five different ways.
Good luck