Alice Community  

Go Back   Alice Community > General Discussion > How do I...?

Reply
 
Thread Tools Display Modes
Spinning Fan Project
Old
  (#1)
debooh
Junior Member
 
Status: Offline
Posts: 2
Join Date: Sep 2009
Default Spinning Fan Project - 11-03-2009, 02:08 PM

I found another way to solve this fan spinning project but I really can't figure out why the attached project does not work. Can anybody enlighten me on what I am doing wrong?



Thank you
Attached Files
File Type: a2w fan speed control 7-28.a2w (545.5 KB, 3 views)
   
Reply With Quote
Old
  (#2)
x2495iiii
Super Moderator
 
x2495iiii's Avatar
 
Status: Offline
Posts: 665
Join Date: Dec 2008
Location: Somewhere in the Continental U.S.
Default 11-03-2009, 11:39 PM

What I'd do is delete all of your boolean variables, then make one number variable called speed under the properties tab of the world (NOT in the method). Then, have the off button set speed to 0 when clicked, the low button set it to one, and so on for the other two buttons. Then, make a new "while the world is running" event which calls one of the methods in the During part of it (which basically means the event wil be called over and over while the world is playing). Finally, have the method that is called in the During part of the event contain a nested if/else if method which looks like this:

if speed == 3
fan.blades roll left .1 revolutions [duration = 0 seconds] [style = abruptly]
else
if speed == 2
etc.

I tried this myself, and it works wonderfully.


This video won a contest I entered for a local company. Hope you guys like it!

http://www.youtube.com/watch?v=4JZKwtDNCIk

Try my newest and biggest game: Resident Penguin.

http://www.alice.org/community/showthread.php?t=3205
   
Reply With Quote
Old
  (#3)
antmj2317
Junior Member
 
Status: Offline
Posts: 9
Join Date: Oct 2009
Default 11-03-2009, 11:56 PM

Quote:
Originally Posted by x2495iiii View Post
What I'd do is delete all of your boolean variables, then make one number variable called speed under the properties tab of the world (NOT in the method). Then, have the off button set speed to 0 when clicked, the low button set it to one, and so on for the other two buttons. Then, make a new "while the world is running" event which calls one of the methods in the During part of it (which basically means the event wil be called over and over while the world is playing). Finally, have the method that is called in the During part of the event contain a nested if/else if method which looks like this:

if speed == 3
fan.blades roll left .1 revolutions [duration = 0 seconds] [style = abruptly]
else
if speed == 2
etc.

I tried this myself, and it works wonderfully.
There's an even easier way.

Create a global variable and give it a starting value of 0

Create events to assign different values to the variable per button.

In 'main', write a single line of code..

while true
fan.blades->roll at speed [global variable] per second

When the event's are executed, the variable in the infinite while loop will have it's value substituted.
   
Reply With Quote
Old
  (#4)
x2495iiii
Super Moderator
 
x2495iiii's Avatar
 
Status: Offline
Posts: 665
Join Date: Dec 2008
Location: Somewhere in the Continental U.S.
Default 11-04-2009, 12:01 AM

That would work too, but you'd have less control over the fan's animation (my code allows for smooth turning and quick stopping, yours yields either choppy animation or slow stopping due to the need for a static, non-zero duration and the fact that the style cannot be changed to abruptly).


This video won a contest I entered for a local company. Hope you guys like it!

http://www.youtube.com/watch?v=4JZKwtDNCIk

Try my newest and biggest game: Resident Penguin.

http://www.alice.org/community/showthread.php?t=3205

Last edited by x2495iiii; 11-04-2009 at 12:05 AM.
   
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Copyright ©2009, Carnegie Mellon University