Alice Community

Alice Community (
-   How do I...? (
-   -   Getting the best of me... (

AliceIsKickingMyButt 11-09-2006 10:52 AM

Getting the best of me...
Just wanted to know if anyone had done (page 199) Chapter 7: Repetition Exercise 8 (speed control). The just of it is placing a fan into a world and writing methods for each button on the fan for different speeds, you have to use nested ifs/whiles to make sure the blades continue to turn until the animation stops or the off button is clicked. I have been working on this for about a week now, I have all methods written and all events set to them so when they are clicked they run. I wrote a method I called fan.buttonClick to simulate the buttons actually being pressed. The only problem is the function I wrote to tell the ifs/whiles that they were true is getting the best of me, I have tried numerous types of functions but haven't found one yet that will work. Also now it seems that my off method isn't working, anyway to make something false so that the if/while statements will just stop everything when I click off? Any thoughts or suggestions on this would be much appreciated.

Shadow Sovereign 11-09-2006 06:51 PM

Wait a couple days, I have an Ideer!
A friend of mine finished that just a couple of days ago. I'm on school vacation right now, but whenever I go back, I'll ask him, see how he did his. I won't post the world and the exact code (knowing about recent going-ons with cheating, which except in single-player games, I disapprove :( ), but I will analyze his work and see where I can help you with this.

Lemme know on any changes with your problem. :)

DrJim 11-09-2006 10:29 PM

Suggestion - Get rid of the complex nesting.
I hadn't looked at that problem before reading your posting - but it's a poster child for the "stepwise refinement" approach the text emphasizes. Don't get locked up in a batch of nested loop/while statements - at least at first. I believe [I]the problem itself gives you a hint[/I] ;) when it says "you may want to use several methods."

I just put together some quick code where the most complicated nesting is one if statement in a method that is called "while the world is running" and which basically controls the motion of the fan based on two world level variables - powerOn and Speed.

I made sure this worked first by manually setting the variables and running the world - then did the rest of the control with a set of statements similar to those in Fig. 5-2-3. Won't claim this approach worked perfectly the first time - but the problem was separated down enough that it was easy to see the problems and fix them. :)

Note: One thing to watch out with this problem is to be sure you have the blades rotating at a slow enough speed, even on high, that the display driver can handle it - otherwise funny things can happen. :eek: (I'd suggest no more than 3 rps maximum. The actual maximum is dependent on your specific hardware but very few drivers even physically refresh the screen faster than 10-12 frames per sec.)

AliceIsKickingMyButt 11-11-2006 11:17 AM

My cpt prof. actually is doing the assignments a chapter ahead of us so she really isn't that much help. She choses to do it the simplest way possible while myself and a few other classmates try and "go overboard" with them. Her functions was bascially "If button is showing true" "return true" I created the method to make it look like a real I am thinking about just doing the minimum requirements and getting it finished.

Also Shadow, thanks for anything you can tell me about your friends. I wouldn't ask you to upload his, I have worked far too hard to take that easy road. I can understand that some people may come here looking for an easy A but if I wanted that I would just set the buttons to showing true/false when I wanted to change speeds.

And DrJim my high rotation is set to 4 rps and it actually distorts the blades and makes it look like they are turn backwards as a real fan would. If I ever get it finished and all the bugs worked out I will be sure to upload.

Once again thanks for the help.

DrJim 11-11-2006 11:31 AM

Hollywood Producer Type Question.
There are advantages to "keeping it simple stupid (KISS)" and also to "going overboard" (I don't see Pixar going broke) - the key thing is to know which you are doing - and it sounds like you do.

Out of curiosity, how does your fan look if you turn off the hardware accelerator and just use software rendering?

All times are GMT -5. The time now is 05:51 AM.

Copyright ©2019, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.