Alice Community  

Go Back   Alice Community > Alice 2 > How do I...?

Reply
 
Thread Tools Display Modes
make while statement work
Old
jccrumbl
Guest
 
Status:
Posts: n/a
Default make while statement work - 03-19-2009, 09:00 AM

I want to make an object move while another object is rotating. I created a method that contains a loop to rotate the object x number of times, which works fine.

I may be completely wrong in my logic, but I want to create a While loop and use the method in place of the True statement. Something like:

While <method name>
Do in order (move the second object)

Is my logic completely off here and anyone have a suggestion on how to make it work? I was thinking I might need to use a function instead of a method, but wasn't sure how to create a funtion to make the object rotate.

Thanks in advance.
   
Reply With Quote
Old
DrJim
Guest
 
Status:
Posts: n/a
Default 03-19-2009, 12:37 PM

Quote:
Originally Posted by jccrumbl View Post
Is my logic completely off here ... need to use a function instead of a method .. funtion to make the object rotate.
Certainly one of the most challenging questions I've seen posted in quite a while. I really suggest after you read this and experiment a bit, you also look again at some references on Alice's while statements, methods and functions (either your text or Dick Baldwin's tutorials). There are a lot of details here that usually don't become clear until after the first reading or two. Also, Alice's (simplified) definitions for methods and functions are a bit different from true Java (and most other languages).

Anyway, here are some brief answers to your questions. Note that these comments apply strictly to Alice 2.0's implementation of method and functions.

1. The test condition in a while statement must evaluate to a boolean value (either true or false). Since an Alice method won't return any value, you can't use a method call for the test condition.

2. You can use a function, provided that the function returns a boolean value.

3. You can't run a method from a function, so you can't use a function to actually make an object rotate.

I enclosed a bit of sample code - not sure whether it will help or just make things more confusing. But anyway, try changing the value of SAM in the function and see what happens.

Also note that, for some reason, in a function you can never delete the last return. But in the example - the code never gets there. The earlier returns (drag and drop from the bottom of the program window) will have returned the boolean value first.
Attached Files
File Type: a2w turn_chicken.a2w (219.4 KB, 25 views)
   
Reply With Quote
A hint for functions
Old
zonedabone
Senior Member
 
zonedabone's Avatar
 
Status: Offline
Posts: 577
Join Date: Nov 2008
Location: In the interwebs
Default A hint for functions - 03-19-2009, 06:59 PM

Whenever I make my own function, I always create a variable called "output". when something want to return a value, it'll set output as that value. The final return will then return "output". This works well for many projects, but I can see how it could hurt some. (methods undoing other methods and things like that)


'Apple Macintosh' - An anagram of 'Complaints Heap'

M.A.C.I.N.T.O.S.H. - Machine Always Crashes, If Not, The Operating System Hangs.

You're *such* a mac person.
   
Reply With Quote
Reply


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 ©2024, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.